Python scapy.utils.PcapWriter() Examples

The following are 11 code examples of scapy.utils.PcapWriter(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module scapy.utils , or try the search function .
Example #1
Source File: scapypipes.py    From scapy with GNU General Public License v2.0 6 votes vote down vote up
def start(self):
        # Wireshark must be running first, because PcapWriter will block until
        # data has been read!
        with ContextManagerSubprocess(conf.prog.wireshark):
            args = [conf.prog.wireshark, "-Slki", "-"]
            if self.args:
                args.extend(self.args)

            proc = subprocess.Popen(
                args,
                stdin=subprocess.PIPE,
                stdout=None,
                stderr=None,
            )

        self.fname = proc.stdin
        WrpcapSink.start(self) 
Example #2
Source File: handshake.py    From pyDot11 with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, psk = None, essid = None, pcap = False):
        self.pt = PE.pt
        if psk is not None and essid is not None:
            if os.path.isfile('handshakes.sqlite'):
                os.remove('handshakes.sqlite')
            self.con = lite.connect('handshakes.sqlite')
            self.con.text_factory = str
            self.db = self.con.cursor()
            self.tgtInfo = {}
            self.availTgts = set()
            self.catchDict = {}
            self.encDict = {}
            self.alert = set()
            self.pke = 'Pairwise key expansion'
            self.pmk = PBKDF2(psk, essid, 4096).read(32)
            self.db.execute('CREATE TABLE IF NOT EXISTS\
                                "shakes"("pkt" TEXT,\
                                         "vmac" TEXT,\
                                         "bmac" TEXT,\
                                         "nonce" TEXT,\
                                         "e_num" TEXT,\
                                         UNIQUE(vmac, bmac, e_num));')
            self.con.commit()
            if pcap is True:
                self.eapolTrack = PcapWriter('eapols.pcap', sync = True)
                self.pcap = pcap
            else:
                self.eapolTrack = None
                self.pcap = None 
Example #3
Source File: scapypipes.py    From scapy with GNU General Public License v2.0 5 votes vote down vote up
def start(self):
        self.f = PcapWriter(self.fname, linktype=self.linktype) 
Example #4
Source File: airpydump.py    From airpydump with MIT License 5 votes vote down vote up
def __init__(self, iface, save, file__, curses):
		self.iface=iface
		self.save=save
		self.file__ = PcapWriter(file__, append=True, sync=True) if self.save else ''
		self.handshakes = 0
		self.stop_hopper = False
		self.thread = self.chain_thread()
		self.curses = curses
		if self.curses:
			self.display = Display(self)
		signal.signal(signal.SIGINT, self.print_exit) 
Example #5
Source File: packetlogger.py    From EvilTwinFramework with GNU General Public License v2.0 5 votes vote down vote up
def pre_scanning(self):
        self.packet_logger = PcapWriter(self.destination_folder + self.current_log_file,
                                        append=True, sync=True)
        SessionManager().log_event(NeutralEvent("Packet Logger initiated.")) 
Example #6
Source File: packetlogger.py    From EvilTwinFramework with GNU General Public License v2.0 5 votes vote down vote up
def refresh(self):
        self._nlogs = self._get_log_count()
        self.packet_logger = PcapWriter(self.destination_folder + "packet_log{n}.cap".format(n = self._nlogs),
        append=True, sync=True) 
Example #7
Source File: sniffer-v1.0.py    From Sniffer with MIT License 5 votes vote down vote up
def __init__(self,
                 iface = '',
                 newiface = 'mon0',
                 filename = '',
                 outputmode = 1,
                 savingPkt = 0,
                 savingPcap = 0,
                 filtermode = '',
                 iHost = []):
	
        self.iface = iface #old interface 
        self.newiface = newiface #a new interface in monitor mode
        self.sign = ['—','\\' ,'|' ,'/'] #stupid thing :)
        self.filename = filename #local pcap filename
	self.sfilename = str(int(time.time()))
        self.outputmode = outputmode #0->don't output, 1->output
	self.savingPkt = savingPkt #0->don't save, 1->save
	self.savingPcap = savingPcap
	self.filtermode = '( tcp[13:1]==24 )' #'tcp[13:1]==24' #only sniff tcp
	self.iHost = iHost
	
	if filtermode: self.filtermode += ' and ( %s )' %filtermode #
	
	if self.savingPkt: InitPktsFile(self.sfilename)
	if savingPcap: self.pktdump = PcapWriter("./Pcaps/%s.pcap" %(self.sfilename), append=True, sync=True)
	    
        if self.iface == '' and filename: 
            print putColor('[!]Offline Mode!', 'green')
	    print '  [-]Filter:', putColor(self.filtermode, 'green')
            pkt = sniff(offline = './Pcaps/' + filename,    
	                prn = self.Collector,    
	                filter = self.filtermode,   
	                store = 0)#DO NOT USING store = 1!!! 
	                          #Or you'll see your memory BOOM
	    print 
	    
        else: self.Init()
	
        self.Exit() 
Example #8
Source File: sniffer-v2.0.py    From Sniffer with MIT License 5 votes vote down vote up
def __init__(self,
                 iface = '',
                 newiface = 'mon0',
                 filename = '',
                 outputmode = 1,
                 savingPkt = 0,
                 savingPcap = 0,
                 filtermode = '',
                 iHost = []):

        self.iface = iface #old interface 
        self.newiface = newiface #a new interface in monitor mode
        self.sign = ['—','\\' ,'|' ,'/'] #stupid thing :)
        self.filename = filename #local pcap filename
        self.sfilename = str(int(time.time()))
        self.outputmode = outputmode #0->don't output, 1->output
        self.savingPkt = savingPkt #0->don't save, 1->save
        self.savingPcap = savingPcap
        self.filtermode = '( tcp[13:1]==24 )' #'tcp[13:1]==24' -> only sniff tcp
        self.iHost = iHost
        
        if filtermode: self.filtermode += ' and ( %s )' %filtermode #

        if self.savingPkt: InitPktsFile(self.sfilename)
        if savingPcap: self.pktdump = PcapWriter("./Pcaps/%s.pcap" %(self.sfilename), append=True, sync=True)

        if self.iface == '' and filename: 
            print putColor('[!]Offline Mode!', 'green')
            print '  [-]Filter:', putColor(self.filtermode, 'green')
            print '  [-]',
            ClearLine() 
            pkt = sniff(offline = './Pcaps/' + filename,    
                        prn = self.Collector,    
                        filter = self.filtermode,   
                        store = 0)#DO NOT USING store = 1!!!              
                                  #Or you'll see your memory BOOM
            print 

        else: self.Init()

        self.Exit() 
Example #9
Source File: sniffer-v2.0-Py3.x.py    From Sniffer with MIT License 5 votes vote down vote up
def __init__(self,
                 iface = '',
                 newiface = 'mon0',
                 filename = '',
                 outputmode = 1,
                 savingPkt = 0,
                 savingPcap = 0,
                 filtermode = '',
                 iHost = []):

        self.iface = iface #old interface 
        self.newiface = newiface #a new interface in monitor mode
        self.sign = ['—','\\' ,'|' ,'/'] #stupid thing :)
        self.filename = filename #local pcap filename
        self.sfilename = str(int(time.time()))
        self.outputmode = outputmode #0->don't output, 1->output
        self.savingPkt = savingPkt #0->don't save, 1->save
        self.savingPcap = savingPcap
        self.filtermode = '( tcp[13:1]==24 )' #'tcp[13:1]==24' -> only sniff tcp
        self.iHost = iHost
        
        if filtermode: self.filtermode += ' and ( %s )' %filtermode #

        if self.savingPkt: InitPktsFile(self.sfilename)
        if savingPcap: self.pktdump = PcapWriter("./Pcaps/%s.pcap" %(self.sfilename), append=True, sync=True)

        if self.iface == '' and filename: 
            print(putColor('[!]Offline Mode!', 'green'))
            print('  [-]Filter:', putColor(self.filtermode, 'green'))
            print('  [-]', end='')
            ClearLine() 
            pkt = sniff(offline = './Pcaps/' + filename,    
                        prn = self.Collector,    
                        filter = self.filtermode,   
                        store = 0)#DO NOT USING store = 1!!!              
                                  #Or you'll see your memory BOOM
            print()

        else: self.Init()

        self.Exit() 
Example #10
Source File: wifibroot.py    From WiFiBroot with GNU General Public License v3.0 5 votes vote down vote up
def save(self):
		global WRITE__
		
		if WRITE__:
			_wr = PcapWriter(WRITE__, append=False, sync=True)
			_wr.write(self.THEPOL)
			pull.use("Handshake >> [%s] Count [%s] %s[Saved]%s" % (pull.DARKCYAN+WRITE__+pull.END, str(len(self.THEPOL)), pull.GREEN, pull.END ))
		else:
			pull.error("Handshake not saved. Use -w, --write for saving handshakes. ") 
Example #11
Source File: sniffer-v3.0.py    From Sniffer with MIT License 4 votes vote down vote up
def __init__(self):       
        parser = argparse.ArgumentParser(description='Version: 3.0; Running in Py2.x')
        parser.add_argument("-i", default='', help="the interface you want to use")
        parser.add_argument("-mi", default='mon0', help="name of the interface in monitor mode")
        parser.add_argument("-f", default='', help="local pcap filename(in the offline mode)")
        parser.add_argument("-o", default='1', help="show msg in the terminal? 0: No, 1: Yes")
        parser.add_argument("-sPkt", default='1', help="save Pkts during snifffing? 0: No, 1: Yes")
        parser.add_argument("-sPcap", default='0', help="save Pcap during snifffing? 0: No, 1: Yes")
        parser.add_argument("-fm", default='', help="filter syntax used in scapy")
        parser.add_argument("-iHF", default='iHost.txt', help="highlight these hosts when stop the sniffer(in the iHost.txt")
        parser.add_argument("-fHF", default='fHost.txt', help="filter these hosts when show msg in terminal(in the fHost.txt")
        args = parser.parse_args() 
        
        self.iface = args.i #old interface 
        self.newiface = args.mi #a new interface in monitor mode
        self.sign = ['—','\\' ,'|' ,'/'] #stupid thing :)
        self.filename = args.f #local pcap filename
        self.sfilename = str(int(time.time()))
        self.outputmode = args.o #0->don't output, 1->output
        self.savingPkt = args.sPkt #0->don't save, 1->save
        self.savingPcap = args.sPcap
        self.filtermode = '( tcp[13:1]==24 )'#'tcp[13:1]==24' -> only sniff tcp
        self.SrcIP = []
        self.fHF = args.fHF
        
        if args.fm: self.filtermode += ' and ( %s )' %args.fm #

        if self.savingPkt == '1': InitPktsFile(self.sfilename)
        if self.savingPcap == '1': self.pktdump = PcapWriter("./Pcaps/%s.pcap" %(self.sfilename), append=True, sync=True)
        
        try:
            with open(args.iHF, 'r') as fp:
                self.iHost = re.findall('(\S+)', fp.read())
        except:
            ErrorDog(self.Exit)
            
        if self.iface == '' and self.filename: 
            print putColor('[!]Offline Mode!', 'green')
            print '  [-]Filter:', putColor(self.filtermode, 'green')
            print '  [-]',
            ClearLine() 
            
            try:
                pkt = sniff(offline = './Pcaps/' + self.filename,    
                        prn = self.Collector,    
                        filter = self.filtermode,   
                        store = 0)#DO NOT USING store = 1!!!              
                                  #Or you'll see your memory BOOM
                print 
            except:
                ErrorDog(self.Exit)
                
        else: self.Init()

        self.Exit()