对网络安全工程师来说,监视网络似乎总是一项有用的任务,因为它使他们能够查看网络中正在发生的事情,查看和控制恶意流量等。在本教程中,您将学会如何嗅探HTTP数据包。

我们继续使用scapy来实现嗅探,一旦检测到HTTP请求,我们将提取一些信息并打印出来,很容易吗?让我们开始吧。
在Scapy 2.4.3+中,默认情况下支持HTTP数据包。让我们安装本教程的要求:
pip3 install scapy colorama
我们这里需要colorama只是为了输出http数据包的时候好看一些。from scapy.all import * from scapy.layers.http import HTTPRequest # import HTTP packet from colorama import init, Fore # initialize colorama init() # define colors GREEN = Fore.GREEN RED = Fore.RED RESET = Fore.RESET
def sniff_packets(iface=None):
"""
Sniff 80 port packets with `iface`, if None (default), then the
Scapy's default interface is used
"""
if iface:
# port 80 for http (generally)
# `process_packet` is the callback
sniff(filter="port 80", prn=process_packet, iface=iface, store=False)
else:
# sniff with default interface
sniff(filter="port 80", prn=process_packet, store=False)
def process_packet(packet):
"""
This function is executed whenever a packet is sniffed
"""
if packet.haslayer(HTTPRequest):
# if this packet is an HTTP Request
# get the requested URL
url = packet[HTTPReq...点击查看剩余70%
网友评论0