<s> '''<STR_LIT>''' <EOL> import dshell <EOL> import util <EOL> import netflowout <EOL> class DshellDecoder ( dshell . TCPDecoder ) : <EOL> '''<STR_LIT>''' <EOL> def __init__ ( self , ** kwargs ) : <EOL> '''<STR_LIT>''' <EOL> self . sessions = { } <EOL> self . alerts = False <EOL> self . file = None <EOL> dshell . TCPDecoder . __init__ ( self , <EOL> name = '<STR_LIT>' , <EOL> description = '<STR_LIT>' , <EOL> longdescription = """<STR_LIT>""" , <EOL> filter = "<STR_LIT>" , <EOL> author = '<STR_LIT>' , <EOL> optiondict = { <EOL> '<STR_LIT:code>' : { '<STR_LIT:type>' : '<STR_LIT:string>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:action>' : '<STR_LIT:store_true>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:action>' : '<STR_LIT:store_true>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:action>' : '<STR_LIT:store_true>' , '<STR_LIT>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:action>' : '<STR_LIT:store_true>' } } ) <EOL> '''<STR_LIT>''' <EOL> self . __decoder = dshell . IPDecoder ( ) <EOL> self . out = netflowout . NetflowOutput ( ) <EOL> self . chainable = True <EOL> def decode ( self , * args ) : <EOL> if len ( args ) is <NUM_LIT:3> : <EOL> pktlen , pktdata , ts = args <EOL> else : <EOL> ts , pktdata = args <EOL> pktlen = len ( pktdata ) <EOL> '''<STR_LIT>''' <EOL> dshell . TCPDecoder . decode ( self , pktlen , pktdata , ts ) <EOL> '''<STR_LIT>''' <EOL> self . __decoder . IPHandler = self . __callback <EOL> self . __decoder . decode ( pktlen , pktdata , ts , raw = pktdata ) <EOL> def __callback ( self , addr , pkt , ts , raw = None , ** kw ) : <EOL> '''<STR_LIT>''' <EOL> if addr in self . sessions or ( addr [ <NUM_LIT:1> ] , addr [ <NUM_LIT:0> ] ) in self . sessions : <EOL> if self . subDecoder : <EOL> self . subDecoder . decode ( len ( raw ) , str ( raw ) , ts ) <EOL> else : <EOL> self . dump ( raw , ts ) <EOL> def connectionInitHandler ( self , conn ) : <EOL> '''<STR_LIT>''' <EOL> m = self . __countryTest ( conn ) <EOL> if m : <EOL> self . sessions [ conn . addr ] = m <EOL> def __countryTest ( self , conn ) : <EOL> if self . code == None or not len ( self . code ) : <EOL> return True <EOL> if self . neither and conn . clientcountrycode != self . code and conn . servercountrycode != self . code : <EOL> return '<STR_LIT>' + self . code <EOL> if self . both and conn . clientcountrycode == self . code and conn . servercountrycode == self . code : <EOL> return '<STR_LIT>' + self . code <EOL> if self . notboth and ( conn . clientcountrycode != self . code or conn . servercountrycode != self . code ) : <EOL> return '<STR_LIT>' + self . code <EOL> if conn . clientcountrycode == self . code : <EOL> return '<STR_LIT>' + self . code <EOL> if conn . servercountrycode == self . code : <EOL> return '<STR_LIT>' + self . code <EOL> return None <EOL> def connectionHandler ( self , conn ) : <EOL> if conn . addr in self . sessions and self . alerts : <EOL> self . alert ( self . sessions [ conn . addr ] , ** conn . info ( ) ) <EOL> def connectionCloseHandler ( self , conn ) : <EOL> if conn . addr in self . sessions : <EOL> del self . sessions [ conn . addr ] <EOL> dObj = DshellDecoder ( ) </s>
