Question: I want to send a HTTP response via scapy to a target system. I know scapy uses layered implementation to create a packet like IP/TCP/ETHER. To send a simple TCP packet we can use the following scapy script.

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

ip=IP(src="10.10.1.207", dst="10.10.1.60")

payload="Hello World"
PUSH=TCP(sport=80, dport=3389, flags="F")
send(ip/PUSH/payload)

```

---

Is there any way we can attach a HTTP layer with this?
I tried many ways however every time I receive a TCP packet instead of a HTTP response packet on the target machine.

Answer: 
**Edit: this is outdated. Since Scapy 2.4.3 you can use [the http layer](https://scapy.readthedocs.io/en/latest/layers/http.html)**

Scapy does not have a native HTTP layer dissector, however, you can send an HTTP request/response easily as it is a textual protocol:

```
RESP  = "HTTP/1.1 200 OK\r\n"
RESP += "Server: exampleServer\r\n"
RESP += "Content-Length: 6\r\n"
RESP += "\r\n"
RESP += "A body"

IP(src="10.10.1.207", dst="10.10.1.60")/TCP(sport=80, dport=3389, flags="A", seq=ACK.ack, ack=ACK.seq)/RESP

```

`ACK` is the third segment of a previously made 3 way handshake (SYN, SYN-ACK, ACK) as this is necessary before sending data over TCP.
Although, Scapy does not have native support for HTTP Layer but there is a python module available for extending the functionality of Scapy to support HTTP layer. The module name is "scapy-http" and can be found on github at [invernizzi/scapy-http](https://github.com/invernizzi/scapy-http).  

You can install it using pip:

```
    sudo pip install scapy-http
```

Here is the example code from github repository:

```

    #!/usr/bin/env python
    try:
        import scapy.all as scapy
    except ImportError:
        import scapy

    try:
        # This import works from the project directory
        import scapy_http.http
    except ImportError:
        # If you installed this package via pip, you just need to execute this
        from scapy.layers import http

    packets = scapy.rdpcap('example_network_traffic.pcap')
    for p in packets:
        print '=' * 78
        p.show()

```

Using this module, you can generate HTTP packets without sending your own text data.