[19377] 2018-07-31_Python大法之告别脚本小子系列---信息资产收集类脚本编写(下)

文档创建者:s7ckTeam
浏览次数:3
最后更新:2025-01-18
2018-07-31_Python大法之告别脚本小子系列---信息资产收集类脚本编写(下) P y t h o n - - - ( ) i   2 0 1 8 - 0 7 - 3 1 i G e x r e x h t t p s : / / g i t h u b . c o m / a s c i i m o o / e x r e x p i p   i n s t a l l   e x r e x
# - * -   c o d i n g :   U T F - 8   - * - i m p o r t   e x r e x   d e f   d i c _ c r e a t e ( h o s t s ) :                 w e b _ d i c s   =   h o s t s . s p l i t ( ' . ' )                 f o r   w e b _ d i c   i n   w e b _ d i c s :                                 f _ p a s s   =   o p e n ( ' p a s s . t x t ' , " r " )                                 f o r   d i c _ p a s s   i n   f _ p a s s : d i c s   =   l i s t ( e x r e x . g e n e r a t e ( w e b _ d i c + ' [ ! @ # ] ' + d i c _ p a s s ) )                                                 f o r   d i c   i n   d i c s :                                                 p r i n t   d i c . s t r i p ( ' n ' )     i f   _ _ n a m e _ _   = =   ' _ _ m a i n _ _ ' :                 d i c _ c r e a t e ( ' w w w . i c h u n q i u . c o m ' ) h t t p : / / , w w w c o m # - * -   c o d i n g :   U T F - 8   - * - i m p o r t   e x r e x   d e f   d i c _ c r e a t e ( h o s t s ) :                 w e b _ d i c s   =   h o s t s . s p l i t ( ' . ' )                 f o r   w e b _ d i c   i n   w e b _ d i c s :                                 i f   w e b _ d i c   n o t   i n   w e b _ w h i t e :                                                 f _ p a s s   =   o p e n ( ' p a s s . t x t ' , " r " )                                                 f o r   d i c _ p a s s   i n   f _ p a s s : d i c s   =   l i s t ( e x r e x . g e n e r a t e ( w e b _ d i c + ' [ ! @ # ] ' + d i c _ p a s s ) )                                                                 f o r   d i c   i n   d i c s :                                                                 p r i n t   d i c . s t r i p ( ' n ' )     i f   _ _ n a m e _ _   = =   ' _ _ m a i n _ _ ' :                 w e b _ w h i t e   =   [ ' c o m ' , ' c n ' , ' o r g ' , ' e d u ' , ' g o v ' , ' w w w ' ]                 h o s t   =   ' w w w . i c h u n q i u . c o m '                 i f   ' : / / '   i n   h o s t :                                 h o s t   =   h o s t . s p l i t ( ' : / / ' ) [ 1 ]                 i f   ' / '   i n   h o s t :                                 h o s t   =   h o s t . r e p l a c e ( ' / ' , ' ' )                 d i c _ c r e a t e ( h o s t ) # - * -   c o d i n g :   U T F - 8   - * - i m p o r t   e x r e x   d e f   d i c _ c r e a t e ( h o s t s ) :                 w e b _ d i c s   =   h o s t s . s p l i t ( ' . ' )                 f o r   w e b _ d i c   i n   w e b _ d i c s :                                 i f   w e b _ d i c   n o t   i n   w e b _ w h i t e :                                                 f _ p a s s   =   o p e n ( ' p a s s . t x t ' , " r " )                                                 f o r   d i c _ p a s s   i n   f _ p a s s : d i c s   =   l i s t ( e x r e x . g e n e r a t e ( w e b _ d i c + ' [ ! @ # ] ' + d i c _ p a s s ) )                                                                 f o r   d i c   i n   d i c s :                                                                                 i f   l e n ( d i c )   >   5 :                                                                                                 p r i n t   d i c . s t r i p ( ' n ' )     i f   _ _ n a m e _ _   = =   ' _ _ m a i n _ _ ' :                 w e b _ w h i t e   =   [ ' c o m ' , ' c n ' , ' o r g ' , ' e d u ' , ' g o v ' , ' w w w ' ]                 h o s t   =   r a w _ i n p u t ( ' P L E A S E   I N P U T   Y O U R   T A R G E T : ' )                 i f   ' : / / '   i n   h o s t :                                 h o s t   =   h o s t . s p l i t ( ' : / / ' ) [ 1 ]                 i f   ' / '   i n   h o s t :                                 h o s t   =   h o s t . r e p l a c e ( ' / ' , ' ' )                 d i c _ c r e a t e ( h o s t )
G I F Q u e u e D : i c h u n q i u i t e m s > p y t h o n P y t h o n   2 . 7   ( r 2 7 : 8 2 5 2 5 ,   J u l     4   2 0 1 0 ,   0 9 : 0 1 : 5 9 )   [ M S C   v . 1 5 0 0   3 2   b i t   ( I n t e l ) ]   o n   w i n 3 2 T y p e   " h e l p " ,   " c o p y r i g h t " ,   " c r e d i t s "   o r   " l i c e n s e "   f o r   m o r e   i n f o r m a t i o n . > > >   i m p o r t   Q u e u e > > >   q u e u e   =   Q u e u e . Q u e u e ( ) > > >   f o r   i   i n   r a n g e ( 8 ) : . . .           q u e u e . p u t ( i ) . . . > > >   q u e u e . q s i z e ( ) 8
> > >   q u e u e . g e t ( ) 0 > > >   q u e u e . g e t ( ) 1 > > >   q u e u e . g e t ( ) 2 T h r e a d i n g Q u e u e # - * -   c o d i n g :   U T F - 8   - * - i m p o r t   t h r e a d i n g i m p o r t   Q u e u e   c l a s s   D e m o R U N ( t h r e a d i n g . T h r e a d ) :         d e f   _ _ i n i t _ _ ( s e l f , q u e u e ) :                 t h r e a d i n g . T h r e a d . _ _ i n i t _ _ ( s e l f )                 s e l f . _ q u e u e   =   q u e u e         d e f   r u n ( s e l f ) :                 w h i l e   n o t   s e l f . _ q u e u e . e m p t y ( ) :                   k e y   =   s e l f . _ q u e u e . g e t ( )                     p r i n t   k e y d e f   m a i n ( ) :         t h r e a d s   =   [ ]         t h r e a d n u m   =   2 0                 # 线         q u e u e   =   Q u e u e . Q u e u e ( )         f o r   i   i n   r a n g e ( 1 , 9 ) :         q u e u e . p u t ( i )         f o r   i   i n   x r a n g e ( t h r e a d n u m ) :         t h r e a d s . a p p e n d ( D e m o R U N ( q u e u e ) )         f o r   t   i n   t h r e a d s :         t . s t a r t ( )         f o r   t   i n   t h r e a d s :           t . j o i n ( ) i f   _ _ n a m e _ _   = =   ' _ _ m a i n _ _ ' :         m a i n ( ) 线 U R l + 访 2 0 0
# - * -   c o d i n g :   U T F - 8   - * - i m p o r t   r e q u e s t s   d e f   s c a n _ t a r g e t _ u r l _ e x i s t s ( t a r g e t _ u r l ) : h e a d e r s = {   ' A c c e p t ' :   ' t e x t / h t m l , a p p l i c a t i o n / x h t m l + x m l , a p p l i c a t i o n / x m l ; q = 0 . 9 , * / * ; q = 0 . 8 ' , ' U s e r - A g e n t ' :   ' M o z i l l a / 5 . 0   ( W i n d o w s   N T   1 0 . 0 ;   W O W 6 4 )   A p p l e W e b K i t / 5 3 7 . 3 6   ( K H T M L ,   l i k e   G e c k o )   C h r o m e / 5 5 . 0 . 2 8 8 3 . 8 7   S a f a r i / 5 3 7 . 3 6 ' ,                 ' A c c e p t - L a n g u a g e ' :   ' z h - C N , z h ; q = 0 . 9 , e n ; q = 0 . 8 ' ,                 ' A c c e p t - E n c o d i n g ' :   ' g z i p ,   d e f l a t e ' ,                 ' R e f e r e r ' :   ' h t t p : / / w w w . g o o g l e . c o m '                 } s t a t u s _ c o d e s   =   [ 2 0 0 ] a l l _ l i n e s = o p e n ( d i r _ f i l e , ' r ' ) . r e a d l i n e s ( ) f o r   i   i n   a l l _ l i n e s : u r l   =   t a r g e t _ u r l + ' / ' + s t r ( i ) r e q = r e q u e s t s . h e a d ( u r l . s t r i p ( ) , t i m e o u t = 8 , h e a d e r s = h e a d e r s )                 i f   r e q . s t a t u s _ c o d e   i n   s t a t u s _ c o d e s : p r i n t ' C O D E : % s , U R L : % s ' % ( s t r ( r e q . s t a t u s _ c o d e ) , u r l . s t r i p ( ' n ' ) . s t r i p ( ' r ' ) ) o p e n ( ' e x i s t s _ t a r g e t _ u r l . t x t ' , ' a ' ) . w r i t e ( u r l )   i f   _ _ n a m e _ _   = =   ' _ _ m a i n _ _ ' :         d i r _ f i l e = ' d e m o . t x t '         t a r g e t _ u r l = ' l o c a l h o s t ' i f t a r g e t _ u r l . s t a r t s w i t h ( ' h t t p : / / ' ) o r   t a r g e t _ u r l . s t a r t s w i t h ( ' h t t p s : / / ' ) :         p a s s         e l s e :         t a r g e t _ u r l   =   ' h t t p : / / '   +   t a r g e t _ u r l         s c a n _ t a r g e t _ u r l _ e x i s t s ( t a r g e t _ u r l ) 线 q u e u e c o d e
# - * -   c o d i n g :   U T F - 8   - * - i m p o r t   r e q u e s t s f r o m   t h r e a d i n g   i m p o r t   T h r e a d ,   a c t i v e C o u n t i m p o r t   Q u e u e   q u e u e   =   Q u e u e . Q u e u e ( ) d i r _ f i l e = ' d e m o . t x t '   d e f   s c a n _ t a r g e t _ u r l _ e x i s t s ( t a r g e t _ u r l ) : h e a d e r s = {                 ' A c c e p t ' :   ' t e x t / h t m l , a p p l i c a t i o n / x h t m l + x m l , a p p l i c a t i o n / x m l ; q = 0 . 9 , * / * ; q = 0 . 8 ' ,                 ' U s e r - A g e n t ' :   ' M o z i l l a / 5 . 0   ( W i n d o w s   N T   1 0 . 0 ;   W O W 6 4 )   A p p l e W e b K i t / 5 3 7 . 3 6   ( K H T M L ,   l i k e   G e c k o )   C h r o m e / 5 5 . 0 . 2 8 8 3 . 8 7   S a f a r i / 5 3 7 . 3 6 ' ,                 ' A c c e p t - L a n g u a g e ' :   ' z h - C N , z h ; q = 0 . 9 , e n ; q = 0 . 8 ' ,                 ' A c c e p t - E n c o d i n g ' :   ' g z i p ,   d e f l a t e ' ,                 ' R e f e r e r ' :   ' h t t p : / / w w w . g o o g l e . c o m ' }         s t a t u s _ c o d e s   =   [ 2 0 0 ]         t r y :                 r e q = r e q u e s t s . h e a d ( t a r g e t _ u r l . s t r i p ( ) , t i m e o u t = 8 , h e a d e r s = h e a d e r s )                 i f   r e q . s t a t u s _ c o d e   i n   s t a t u s _ c o d e s : p r i n t ' C O D E : % s , U R L : % s ' % ( s t r ( r e q . s t a t u s _ c o d e ) , t a r g e t _ u r l . s t r i p ( ' n ' ) . s t r i p ( ' r ' ) )                         o p e n ( ' e x i s t s _ t a r g e t _ u r l . t x t ' , ' a ' ) . w r i t e ( t a r g e t _ u r l )         e x c e p t :         p a s s d e f   o p e n _ p a t h f i l e ( f i l e ) :         a l l _ l i n e s = o p e n ( f i l e , ' r ' ) . r e a d l i n e s ( )         f o r   l i n e   i n   a l l _ l i n e s :         i f   t a r g e t _ u r l . e n d s w i t h ( ' / ' ) :         i f   l i n e . s t a r t s w i t h ( ' / ' ) :         q u e u e . p u t ( t a r g e t _ u r l + l i n e [ 1 : ] )         e l s e :                                 q u e u e . p u t ( t a r g e t _ u r l   +   l i n e )           e l s e :                                 i f   l i n e . s t a r t s w i t h ( ' / ' ) :                                 q u e u e . p u t ( t a r g e t _ u r l   +   l i n e )             e l s e :                                 q u e u e . p u t ( t a r g e t _ u r l   +   ' / '   +   l i n e )   i f   _ _ n a m e _ _   = =   ' _ _ m a i n _ _ ' :         p r i n t   ' ' '   _ _ _ _     _             _ _ _ _                                     |     _   ( _ ) _   _ _ /   _ _ _ |     _ _ _   _ _   _   _   _ _     |   |   |   |   |   ' _ _ _ _ _     /   _ _ /   _ `   |   ' _     |   | _ |   |   |   |       _ _ _ )   |   ( _ |   ( _ |   |   |   |   | | _ _ _ _ / | _ | _ |     | _ _ _ _ /   _ _ _ _ _ , _ | _ |   | _ |           ' ' '       t a r g e t _ u r l = r a w _ i n p u t ( ' P l e a s e   i n p u t   y o u r   t a r g e t : ' )       t h r e a d n u m   =   r a w _ i n p u t ( ' P l e a s e   i n p u t   y o u r   t h r e a d n u m : ' )         i f   t a r g e t _ u r l . s t a r t s w i t h ( ' h t t p : / / ' )   o r   t a r g e t _ u r l . s t a r t s w i t h ( ' h t t p s : / / ' ) :         p a s s         e l s e :                 t a r g e t _ u r l   =   ' h t t p : / / '   +   t a r g e t _ u r l         p r i n t   ' T h e   n u m b e r   o f   t h r e a d s   i s   % s '   %   t h r e a d n u m         p r i n t   ' M a t c h i n g . . . . . . . '         o p e n _ p a t h f i l e ( d i r _ f i l e )         w h i l e   q u e u e . q s i z e ( )   >   0 :         i f   a c t i v e C o u n t ( )   < =   i n t ( t h r e a d n u m ) :                         T h r e a d ( t a r g e t = s c a n _ t a r g e t _ u r l _ e x i s t s , a r g s = ( q u e u e . g e t ( ) , ) ) . s t a r t ( )
C C . . A D O i p 访 i p d a l a o
# - * -   c o d i n g :   U T F - 8   - * - i m p o r t   r e q u e s t s i m p o r t   t h r e a d i n g i m p o r t   Q u e u e i m p o r t   s y s i m p o r t   i p a d d r   c l a s s   P o r t S c a n ( t h r e a d i n g . T h r e a d ) :         d e f   _ _ i n i t _ _ ( s e l f , q u e u e ) :         t h r e a d i n g . T h r e a d . _ _ i n i t _ _ ( s e l f )         s e l f . _ q u e u e   =   q u e u e         s e l f . h e a d e r s   =   { ' U s e r - A g e n t ' :   ' M o z i l l a / 5 . 0   ( W i n d o w s   N T   1 0 . 0 ;   W O W 6 4 )   A p p l e W e b K i t / 5 3 7 . 3 6   ( K H T M L ,   l i k e   G e c k o )   C h r o m e / 5 5 . 0 . 2 8 8 3 . 8 7   S a f a r i / 5 3 7 . 3 6 ' , }         d e f   r u n ( s e l f ) :           w h i l e   T r u e :           i f   s e l f . _ q u e u e . e m p t y ( ) :                                 b r e a k             t r y :                                 i p   =   s t r ( s e l f . _ q u e u e . g e t ( t i m e o u t = 5 ) )                                 u r l   =   ' h t t p : / / '   +   i p                               r =   r e q u e s t s . g e t ( u r l = u r l , h e a d e r s = s e l f . h e a d e r s , t i m e o u t = 5 )                                 s t a t u s   =   r . s t a t u s _ c o d e                                 i f   s t a t u s :                                 s y s . s t d o u t . w r i t e ( " % - 2 7 s n "   %   ( u r l ) )                                 e x c e p t   E x c e p t i o n :                                 p a s s d e f   m a i n ( ) :         i f   l e n ( s y s . a r g v )   ! =   2 :         p r i n t   ' U s a g e :   p y t h o n   % s   1 9 2 . 1 6 8 . 1 . 1 / 2 4 ' % ( s y s . a r g v [ 0 ] )           e l s e :                 t h r e a d s   =   [ ]                 t h r e a d n u m   =   2 5 0                 # 线                 q u e u e   =   Q u e u e . Q u e u e ( )                 c i d r i p   =   s y s . a r g v [ 1 ]             # I P                 i p s   =   i p a d d r . I P N e t w o r k ( c i d r i p )                 f o r   i p   i n   i p s :                         q u e u e . p u t ( i p )                 f o r   i   i n   x r a n g e ( t h r e a d n u m ) :                         t h r e a d s . a p p e n d ( P o r t S c a n ( q u e u e ) )                 f o r   t   i n   t h r e a d s :                         t . s t a r t ( )                 f o r   t   i n   t h r e a d s :                         t . j o i n ( )                 p r i n t   ' A L L   F i n i s h e d ! ' i f   _ _ n a m e _ _   = =   ' _ _ m a i n _ _ ' :         m a i n ( )
~
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则