Trying to extract URL using packet sniffer and scapy, but it doesn’t return the URL of the website

  packet-sniffers, python, scapy

I was trying to build a packet sniffer using scapy and I followed the steps mentioned in a tutorial. I did this on a Kali Linux Virtual Machine. This keeps giving me a different output compared to what was shown in tutorial. I checked on other websites as well and many of those used a similar code and their output was same as the tutorial. It shows "ocsp.pki.goog/gts1c3" as the URL. This is the screenshot for the result. This is the code I used:

#!/usr/bin/env python
import scapy.all as scapy
from scapy.layers import http


def sniff(interface):
    scapy.sniff(iface=interface, store=False, filter="tcp", prn=process_sniffed_packet)


def process_sniffed_packet(packet):
    if packet.haslayer(http.HTTPRequest):
        url = packet[http.HTTPRequest].Host + packet[http.HTTPRequest].Path
        print(url)

sniff(eth0)

Source: Python Questions

LEAVE A COMMENT