-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
basic_example.py
49 lines (40 loc) · 2.23 KB
/
basic_example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# ,---. ,--. ,--. ,--. ,--. ,--. by Nemesis Mr.Chess #
# ' .-' | ,---. ,---. ,--.--.| | ,---. ,---.| |,-. ,---. | '--' | ,---. ,--,--,--. ,---. #
# `. `-. | .-. || .-. :| .--'| || .-. || .--'| / ( .-' | .--. || .-. || || .-. : #
# .-' || | | |\ --.| | | |' '-' '\ `--.| \ \ .-' `)| | | |' '-' '| | | |\ --. #
# `-----' `--' `--' `----'`--' `--' `---' `---'`--'`--'`----' `--' `--' `---' `--`--`--' `----' #
# Will get all Bastards! #
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
from scapy.all import *
import csv
import time
import re
onion_address = "INSERT .ONION ADDRESS HERE" # .onion address you want to monitor
packet_list = []
def packet_capture(packet):
if packet.haslayer(IP):
if packet[IP].dst == onion_address or packet[IP].src == onion_address:
timestamp = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(packet.time))
src_ip = packet[IP].src
dst_ip = packet[IP].dst
protocol = packet[IP].proto
packet_list.append([timestamp, src_ip, dst_ip, protocol])
while True:
sniff(prn=packet_capture, filter=f"host {onion_address}", count=10)
# Write packet data to CSV file
with open('onion_communication.csv', mode='w', newline='') as file:
writer = csv.writer(file)
writer.writerow(['Timestamp', 'Source IP', 'Destination IP', 'Protocol'])
for row in packet_list:
writer.writerow(row)
# Check destination
for pkt in packet_list:
ip_src = pkt[1]
ip_dst = pkt[2]
if re.match(r'127\.0\.0\.1:(8080|8081|8083)', ip_dst):
print(f'Potential intruder detected: {ip_src} -> {ip_dst}')
# Reset packet_list
packet_list = []
# Add a delay or other logic as needed
time.sleep(60) # Wait for 1 minute before capturing the next batch of packets