Skip to content
Snippets Groups Projects
Commit 0ff33741 authored by Byron Lathi's avatar Byron Lathi
Browse files

Use scapy to send real packets

parent 68fe3d18
No related branches found
No related tags found
2 merge requests!76Resolve "Send TCP data over M2S",!74Resolve "Network Processor"
from scapy.layers.inet import Ether, IP, TCP
from scapy.layers.l2 import ARP
from scapy import sendrecv
from scapy.config import conf
from scapy.supersocket import L3RawSocket
import socket
# In order for this to work, you need to run these commands:
# sudo setcap cap_net_raw=eip $(readlink -f $(which python))
# sudo iptables -A OUTPUT -p tcp --tcp-flags RST RST -s 127.0.0.1 -j DROP
def main():
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serversocket.bind(("127.0.0.1", 5678))
serversocket.listen(5)
conf.L3socket = L3RawSocket
tcp_syn = IP(dst="127.0.0.1")/TCP(sport=1234, dport=5678, seq=0, ack=0, flags="S")
sendrecv.send(tcp_syn, iface="lo")
pkt = sendrecv.sniff(filter="tcp src port 5678", iface="lo", count=1)[0]
print(pkt)
if __name__ == "__main__":
main()
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment