Transparently sniffing and modify traffic with scapy in-path

January 29, 2017 at 19:42 (linux) (, , , , )

I decided to play a little bit with scapy and tried to find something in the internet that helped me to sniff and modify traffic without ARP-Storming the whole network.

I want to connect a box to my computer eth0 and the network to eth1, so that I’m between the box and the network.

Note: This one does not defeat SSL right now, but that could be easily done with all the tools out there.

The idea is to transparently forward all traffic and only pick out specific packets for modification with scapy.

I did do this with an combination of bridged interface, iptables NFQueue and scapy.

First we gonna create a bridge between eth0 and eth1 to transparently forward all traffic:

ifconfig eth0
ifconfig eth1
brctl addbr br0
brctl addif br0 eth0 eth1
ifconfig br0 up

Second, we need to setup iptables to send the traffic we want to change to an NFQueue.
Important is that this line is executed within the startup of the scapy script, so the actual modding only happens if the script is running.
It would be bad if the script is not running and the packets don’t traverse..

The line we need to set in the scapy script is:

iptables -A FORWARD -m physdev –physdev-in eth1  -s -j NFQUEUE

Third, our scapy program catches those packets, modify them if they are of interest for us and forwards them accordingly.
Important is to command scapy that it should also forward traffic we do not want to be modified (e.g. other SNMP calls in this example):

What I actually do is to modify a response of our target system to the monitoring system.
I choose the SNMP response of an HP ProLiant power-supply check that checks if the power supplies are OK or not (or disconnected):

The “original” says that both power-supplies are degraded or in other words they have a problem:

# snmpwalk -v 1 -c public -O eq
iso. 3
iso. 3

# ./check_psu -H

after starting the scapy script, it will happily transform to something much better:

Adding iptable rules :
iptables -A FORWARD -m physdev –physdev-in eth1 -s -p udp -j NFQUEUE
[+] Running Main loop
Got a packet ! source ip : dest:
Old status: 2 (<ASN1_OID[‘.’]>)
New status: 2 (OK)
Got a packet ! source ip : dest:
Old status: 2 (<ASN1_OID[‘.’]>)
New status: 2 (OK)

and in the console:

# snmpwalk -v 1 -c public -O eq
iso. 2
iso. 2

# ./check_psu -H

And this all by just carefully crafting and modifying packets

Have Phun :)


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: