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

def findWeb():
    a = sr1(IP(dst="8.8.8.8")/UDP()/DNS(qd=DNSQR(qname="www.google.com")),verbose=0)
    return a[DNSRR].rdata

def sendPacket(dst,src):
    ip = IP(dst = dst)
    SYN = TCP(sport=1500, dport=80, flags='S')
    SYNACK = sr1(ip/SYN)

    my_ack = SYNACK.seq + 1
    ACK = TCP(sport=1050, dport=80, flags='A', ack=my_ack)
    send(ip/ACK)

    payload = "stuff"
    PUSH = TCP(sport=1050, dport=80, flags='PA', seq=11, ack=my_ack)
    send(ip/PUSH/payload)


    http = sr1(ip/TCP()/'GET /index.html HTTP/1.0 \n\n',verbose=0)
    print http.show()

src = '10.0.0.24'
dst = findWeb()
sendPacket(dst,src)

I'm trying to do HTTP packets with SCAPY I am using UBUNTU on VMwaer

The problem is that every time I send messages I have RESET How do we fix it?

Thanks

sniff package image

yonatan
  • 23
  • 1
  • 10

1 Answers1

0

Few things I notice wrong. 1. You have your sequence number set statically (seq=11) which is wrong. Sequence numbers are always randomly generated and they must be used as per RFC793. So the sequence should be = SYNACK[TCP].ack

  1. You set your source port as 1500 during SYN packet, but then you use it as 1050 (typo?)

  2. You don't need extra payload/PUSH.

Also, have a look at these threads:

How to create HTTP GET request Scapy?

Python-Scapy or the like-How can I create an HTTP GET request at the packet level

Community
  • 1
  • 1
Danail Petrov
  • 1,875
  • 10
  • 12