How to generate socket errors on a network bridge

I am trying to create a test environment to test the handling of network errors between a client and a server. I also can not change the software. Both devices will be connected via the Linux bridge, and I will use various bandwidth shaping tools to limit bandwidth or block traffic in general to simulate various error conditions.

Another thing I need to do that I still don’t know how to achieve is to generate socket errors in existing connections. I would prefer to use an existing Linux tool / utility, but maybe I can write my own with enough guidance. I am well acquainted with core networks, TCP and UDP and all that, but not with the bridge.

Can someone suggest a way I can generate socket errors, for example. by running unexpected FIN packets on both ends of a socket that connects through a bridge?

Thanks in advance.

+3
source share
1 answer

You can create, with scapy, FIN or RST packets that sniff easily in the bridge (usually br0) and process the corresponding RST or FIN packets.

Here is an example where RST is sent in the same direction of a data packet.

#!/usr/bin/python
from scapy.all import *
import random

def sendRST(p):
    flags = p.sprintf("%TCP.flags%")
    if flags != "S":
        ip = p[IP]      # Received IP Packet
        tcp = p[TCP]    # Received TCP Segment
        if ip.len   <= 40:
            return
        i = IP()        # Outgoing IP Packet
        i.dst = ip.dst
        i.src = ip.src
        t = TCP()       # Outgoing TCP Segment
        t.flags = "R"
        t.dport = tcp.dport
        t.sport = tcp.sport
        t.seq = tcp.seq
        new_ack = tcp.seq + 1
        print "RST sent to ",i.dst,":",t.dport
        send(i/t)

while (1):
PKT = sniff (iface = "br0", filter = "tcp and src host x.x.x.x", count=1, prn=sendRST)
exit()

Check out the sniff options which are extremely powerful :)

Hope to help you.

+4
source

All Articles