Sending a payload with scapy

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 how to use Python Scapy. I could not understand what is raw. Why to send a payload I need to raw = Raw(b"Olaa") ? I also did not understand why passing a tuple in ans,unans = sr(pkt) Could someone please clarify?

    
asked by anonymous 12.08.2016 / 22:54

1 answer

1

Raw is a class of the packet.py file of Scapy . You can view 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 preceding the string in Python 2 is ignored :

  

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

In Python 3, according to documentation :

  

(In free translation)

     

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

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

    
12.08.2016 / 23:59