[11744] 2017-09-04_利用Python实现DGA域名检测

文档创建者:s7ckTeam
浏览次数:4
最后更新:2025-01-18
2017-09-04_利用Python实现DGA域名检测 P y t h o n D G A   f e i n i a o   F r e e B u f   2 0 1 7 - 0 9 - 0 4 x s h e l l D N S x s h e l l 1 .  
2 .   X s h e l l D N S t x t D N S D G A D G A D G A D N S D G A D G A 1 .   D G A 3 6 0 2 .   D G A D G A D G A D N S D G A   h t t p : / / w w w . f r e e b u f . c o m / g e e k / 1 4 4 4 5 9 . h t m l 3 .   D G A h t t p : / / w w w . f r e e b u f . c o m / a r t i c l e s / n e t w o r k / 1 3 9 6 9 7 . h t m l ( ) D N S D N S D G A I P D G A 3 6 0 D G A 1 0 0 W + D G A h t t p : / / d a t a . n e t l a b . 3 6 0 . c o m / f e e d s / d g a / d g a . t x t
D N S D G A D G A I P D G A I P I P P a s s i v e   D N S D G A
D G A D N S
f e i n i a o   F r e e B u f   # c o d i n g : u t f - 8 i m p o r t   t i m e f r o m   s c a p y . a l l   i m p o r t   * f r o m   r e q u e s t s   i m p o r t   * c o n f . i f a c e = ' I n t e l ( R )   D u a l   B a n d   W i r e l e s s - A C   8 2 6 0 ' l i s t = [ ] d g a l i s t   =   o p e n ( ' d g a . t x t ' , ' r ' ) d g a l i s t   =   ( d g a l i s t . r e a d l i n e s ( ) ) [ 1 8 : ] f o r   d g a   i n   d g a l i s t   :         l i s t . a p p e n d ( d g a . s p l i t ( ' t ' ) [ 1 ] ) d a t a   =   s e t ( l i s t ) # C a p t u r e   a n d   F i l t e r   D G A d e f   c a p t u r e ( p a c k e t ) :         i f   p a c k e t :                 i   = 0                 f o r   p   i n   p a c k e t :                         s r c   =   p [ i ] [ I P ] . s r c                         d s t   =   p [ i ] [ I P ] . d s t                         s p o r t   =   p [ i ] [ U D P ] . s p o r t                         d p o r t   =   p [ i ] [ U D P ] . d p o r t                         q r   =   s t r ( p [ i ] [ D N S ] . q r )                         r c o d e   =   s t r ( p [ i ] [ D N S ] . r c o d e )                         i f   ' 0 '   i n   q r :                                 q r   =   ' Q u e r y '                                 q n a m e   =   p [ i ] [ D N S ] . q d . q n a m e                                 i f   t y p e ( q n a m e )   = =   b y t e s :                                         q n a m e   =   ( q n a m e . d e c o d e ( ' u t f - 8 ' ) ) [ : - 1 ]                                 i f   q n a m e   i n   d a t a :                                         p r i n t ( " [ * ]   F o u n d   D G A   R e q u e s t : - - > " , s r c , s p o r t , q r , q n a m e )                         i f   ' 1 '   i n   q r :                                 i f   ' 0 '   i n   r c o d e :                                         f o r   j   i n   r a n g e ( 1 0 ) :                                                 t r y :                                                         q r   =   ' R e s p o n s e '                                                         r r n a m e   =   p [ j ] [ D N S ] . a n [ j ] . r r n a m e                                                         r d a t a   =   p [ j ] [ D N S ] . a n [ j ] . r d a t a                                                         i f   t y p e ( r r n a m e )   = =   b y t e s :                                                                 r r n a m e   =   ( r r n a m e . d e c o d e ( ' u t f - 8 ' ) ) [ : - 1 ]                                                                 i f   t y p e ( r d a t a )   = =   b y t e s :                                                                         r d a t a   =   ( r d a t a . d e c o d e ( ' u t f - 8 ' ) ) [ : - 1 ]                                                         i f   r r n a m e   i n   d a t a :                                                                 p r i n t   ( " [ * ]   F o u n d   D G A   R e s p o n s e : - - > " , s r c , d s t , q r , r r n a m e , r d a t a , " n " )                                                 e x c e p t   E x c e p t i o n   a s   e :                                                         p a s s                 i   =   i   +   1 # u p d a t e   d g a f i l e d e f   d g a f i l e u p d a t e ( ) :         u r l   =   ' h t t p : / / d a t a . n e t l a b . 3 6 0 . c o m / f e e d s / d g a / d g a . t x t '         d g a f i l e   =   g e t ( u r l )         w i t h   o p e n ( ' . / d g a . t x t ' , ' w ' )   a s   f :                 f . w r i t e ( d g a f i l e . t e x t )                 p r i n t ( ' D o w n l o a d   D G A F i l e   F i n i s h e d ' ) i f   _ _ n a m e _ _   = =   ' _ _ m a i n _ _ ' :         s n i f f ( p r n = c a p t u r e , f i l t e r = ' u d p   p o r t   5 3 ' )         w h i l e   T r u e :                 d g a f i l e u p d a t e ( )                 t i m e . s l e e p ( 8 6 4 0 0 )

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则