forked from abdoxfox/HTTP-CUSTOM-HEADERS-VPN
-
Notifications
You must be signed in to change notification settings - Fork 2
/
ssh.py
116 lines (95 loc) · 3.68 KB
/
ssh.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
import subprocess
import socket
import threading
import random
import time
import sys,os,re
import configparser
# colors
bg=''
G = bg+'\033[32m'
O = bg+'\033[33m'
GR = bg+'\033[37m'
R = bg+'\033[31m'
class sshRunn:
def __init__(self,inject_port,):
self.inject_host = '127.0.0.1'
self.inject_port = inject_port
def ssh_client(self,socks5_port,host,port,user,password,mode):
try:
dynamic_port_forwarding = '-CND {}'.format(socks5_port);threading.Lock().acquire()
host = host
port = port
username = user
password = password
inject_host= self.inject_host
inject_port= self.inject_port
nc_proxies_mode = [f'nc -X CONNECT -x {inject_host}:{inject_port} %h %p',f'corkscrew {inject_host} {inject_port} %h %p']
arg = str(sys.argv[1])
if arg == '2':
proxycmd =f'-o "ProxyCommand={nc_proxies_mode[0]}"'
elif arg =='1':
proxycmd = f'-o "ProxyCommand={nc_proxies_mode[1]}"'
elif arg =='0':
self.logs("Connecting Using Direct SSH " )
proxycmd =''
if self.enableCompress=='y':
compress = "-C"
else:compress =""
response = subprocess.Popen(
(
f'sshpass -p {password} ssh {compress} {proxycmd} {username}@{host} -p {port} -v {dynamic_port_forwarding} ' + '-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null '
),
shell=True,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
for line in response.stdout:
line = line.decode('utf-8',errors='ignore')
print(line)
if 'compat_banner: no match:' in line:
self.logs(f"{G}handshake starts\nserver :{line.split(':')[2]}")
elif 'Server host key' in line:self.logs(line)
elif 'kex: algorithm:' in line:self.logs(line)
elif 'kex: host key algorithm:' in line:self.logs(line)
elif 'kex: server->client cipher:' in line:self.logs(line)
elif 'Next authentication method: password' in line:self.logs(G+'Authenticate to password'+GR)
elif 'Authentication succeeded (password).' in line:self.logs('Authentication Comleted')
elif 'pledge: proc' in line:self.logs(G+'CONNECTED SUCCESSFULLY '+GR)
elif 'pledge: network' in line:self.logs(G+'CONNECTED SUCCESSFULLY '+GR)
elif 'Permission denied' in line:self.logs(R+'username or password are inncorect '+GR)
elif 'Connection closed' in line:self.logs(R+'Connection closed ' +GR)
elif 'Could not request local forwarding' in line:self.logs(R+'Port used by another programs '+GR);
except KeyboardInterrupt:
sys.exit('stoping ..')
def create_connection(self,host,port,user,password,mode):
global soc , payload
try:
regx = r'[a-zA-Z0-9_]'
if re.match(regx,host):
try:
ip = socket.gethostbyname(host)
except:
ip = host
sockslocalport = 1080
sshthread = threading.Thread(target=self.ssh_client,args=(sockslocalport,ip,port,user,password,mode))
sshthread.start()
except ConnectionRefusedError:
pass
except KeyboardInterrupt :
self.logs(R+'ssh stopped'+GR);threading.Lock().release()
def logs(self,log):
with open('logs.txt','a') as file:
file.write(log+'\n')
def main(self):
config = configparser.ConfigParser()
config.read_file(open('settings.ini'))
host = config['ssh']['host']
mode = config['mode']['connection_mode']
port = config['ssh']['port']
user = config['ssh']['username']
password = config['ssh']['password']
self.enableCompress = config['ssh']['enable_compression']
self.create_connection(host,port,user,password,mode)
localport= sys.argv[2]
start = sshRunn(localport)
start.main()