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

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

本版积分规则