-
Notifications
You must be signed in to change notification settings - Fork 3
/
exshell.py
90 lines (87 loc) · 3.1 KB
/
exshell.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
84
85
86
87
88
89
90
import pinjection
import testmodule
import constantsfile
def shell(pid):
pinject = pinjection.Inject(
pid,
function = testmodule.test_function,
constants = constantsfile.get_constants(),
verbose = True
)
cmd = input("> ")
while not cmd in ("exit", "quit"):
if cmd == "inject":
pinject.inject()
elif cmd == "deallocate":
pinject.deallocate()
elif cmd == "read":
try:
if pinject.base_addr == 0:
pass
else:
pinject.base_addr = int(input("Set the base address to read: "))
except Exception as err:
print(f"Exception occurred: {str(err)}")
if pinject.base_addr == 0:
pass
else:
pinject.read()
elif cmd == "execute":
try:
if pinject.base_addr == 0:
pass
else:
pinject.base_addr = int(input("Set the base address to read: "))
except Exception as err:
print(f"Exception occurred: {str(err)}")
if pinject.base_addr == 0:
pass
else:
pinject.execute()
elif cmd == "printobj":
pinject.printObj()
elif cmd == "set baseaddr":
try:
if pinject.base_addr == 0:
pass
else:
pinject.base_addr = int(input("Set the base address to read: "))
except Exception as err:
print(f"Exception occurred: {str(err)}")
elif cmd == "set buffsize":
try:
pinject.buffsize = int(input("Buffer size: "))
pinject.buff = bytes(pinject.buffsize)
except Exception as err:
print(f"Exception occurred: {str(err)}")
elif cmd == "verbose":
if pinject.verbose:
pinject.verbose = False
else:
pinject.verbose = True
print(f"Verbose set to {pinject.verbose}")
elif cmd == "debug":
if pinject.debug:
pinject.debug = False
else:
pinject.debug = True
print(f"Debug set to {pinject.debug}")
elif cmd in ("?", "help", "ayuda"):
print("""
Help message:
inject: Inject into the given PID
deallocate: Deallocate the memory region with base address of Inject.base_addr")
read: Prompt the base address (if it is 0) then read the memory region of it
execute: Prompt the base address (if it is 0) then execute the memory region of it
set baseaddr: Ask the base address to set
set buffsize: Ask the buffer size (this will also set the current buffer to a bytearray of the entered number, overwriting any previous saved buffer.)
verbose: Enable/disable verbosity
debug: Enable/disable debug
exit/quit: Quit application
""")
else:
print("Invalid command")
cmd = input("> ")
if __name__ == '__main__':
_pid = int(input("PID: "))
shell(_pid)