-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtor_scapy_app.py
75 lines (60 loc) · 2 KB
/
tor_scapy_app.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
### `tor_scapy_app.py`
### Nemesis Mr. Chess
from stem import Signal
from stem.control import Controller
from stem.process import launch_tor_with_config
from scapy.all import *
import socks
import socket
import time
def start_tor_process():
print("Starting Tor process...")
tor_process = launch_tor_with_config(
config = {
# add your configs here!
'SocksPort': '9050',
'ControlPort': '9051',
},
init_msg_handler = lambda line: print(line),
)
return tor_process
def connect_to_tor():
print("Connecting to Tor...")
with Controller.from_port(port = 9051) as controller:
controller.authenticate()
print("Tor Version:", controller.get_version())
print("Allowed SocksPort:", controller.get_conf("SocksPort"))
return controller
def request_new_identity(controller):
print("Requesting new identity...")
controller.signal(Signal.NEWNYM)
time.sleep(5) # Wait for Tor to switch to a new identity
print("New identity has been requested")
def send_packet_via_tor(destination):
print(f"Sending packet to {destination} via Tor...")
socks.set_default_proxy(socks.SOCKS5, "127.0.0.1", 9050)
socket.socket = socks.socksocket
packet = IP(dst=destination)/ICMP()
response = sr1(packet, timeout=10)
if response:
response.show()
else:
print("No response received")
if __name__ == "__main__":
try:
# Start a new Tor process
tor_process = start_tor_process()
# Connect to the running Tor process
controller = connect_to_tor()
# Request a new identity
request_new_identity(controller)
# Send a packet via Tor
# Example
destination_ip = "8.8.8.8"
send_packet_via_tor(destination_ip)
except Exception as e:
print(f"An error occurred: {e}")
finally:
if 'tor_process' in locals():
print("Terminating Tor process...")
tor_process.terminate()