Sending a payload with scapy

Asked

Viewed 418 times

1

from scapy.all import *

ip = IP(dst = "192.168.1.1")

tcp = TCP (dport = 80, flags = "S")


raw = Raw(b"Olaa")

pkt = ip/tcp/raw

sr(pkt)

ans,unans = sr(pkt)

I’m learning to use Python Scapy. I couldn’t figure out what raw is. Why to send a payload I need to do raw = Raw(b"Olaa") ? I also didn’t understand why to pass a tuple on ans,unans = sr(pkt) Could someone please clarify?

1 answer

1


Raw is a file class packet.py of Scapy. You can see the source code here.

class Raw(Packet):
     name = "Raw"
     fields_desc = [ StrField("load", "") ]
     def answers(self, other):
         return 1
         #s = str(other)
         #t = self.load
         #l = min(len(s), len(t))
         #return  s[:l] == t[:l]
     def mysummary(self):
         cs = conf.raw_summary
         if cs:
             if callable(cs):
                 return "Raw %s" % cs(self.load)
             else:
                 return "Raw %r" % self.load
         return Packet.mysummary(self)

The letter b or B prior to string in Python 2 is ignored:

A prefix b or B is ignored in Python 2; this indicates that literal should become a byte literal in Python 3. The prefix u or b can be followed by a prefix r.

In Python 3, according to documentation:

(In free translation)

Bytes literals are always prefixed with b or B; they produce an instance of the bytes instead of the kind str. They can only contain ASCII characters; bytes with a numerical value of 128 or greater must be expressed with escapes.

You must pass the variables ans and unans because the function sr returns a tuple returning unanswered packages and responses and packages.

  • I am using python3. They said that in python 2 we use: Raw("Olaa") without b in front. They said that b is placed in python3... It’s true?

  • 1

    @Paulsigonoso Yes. In Python 2 o b is ignored as you can read in documentation.

  • What is pkt = ip/tcp/raw ?

  • 1

    @Paulsigonoso Place in pkt the ip, information from door and the raw. Take a look at this article on..: https://thepacketgeek.com/scapy-p-06-sending-and-receiving-with-scapy/

  • 1

    thanks for the help!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.