Skip to content

Instantly share code, notes, and snippets.

@ralphbean
Created November 30, 2012 19:08
Show Gist options
  • Select an option

  • Save ralphbean/4177812 to your computer and use it in GitHub Desktop.

Select an option

Save ralphbean/4177812 to your computer and use it in GitHub Desktop.
Try connecting to a netcat instance with scapy on port 9001
#!/usr/bin/env python
# The above line indicates that this is a python script.
# Author: Ralph Bean <rbean@redhat.com>
# This line imports python objects from the scapy module
from scapy.all import sendp, TCP, IP
# Can we get scapy to talk with netcat?
# http://stackoverflow.com/questions/12062781/how-to-make-netcat-display-payload-of-packet
# Run "nc -l 9001"
# This will send one empty packet to tcp://127.0.0.1:9001
print sendp(TCP(dport=9001) / IP(dst="127.0.0.1"))
# It doesn't do a full tcp handshake, though. We have to use SocketStream for
# that. http://trac.secdev.org/scapy/wiki/TCP
import socket
from scapy.all import StreamSocket, Raw
s = socket.socket()
s.connect(("127.0.0.1", 9001))
ss = StreamSocket(s, Raw)
ss.sr1(Raw("Hello World"))
# * What kind of payload is a zeromq SUB socket expecting?
# (It's described here http://rfc.zeromq.org/spec:2 )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment