from
itertools
import
permutations
import
sys
import
time
import
frida
result
=
""
received
=
False
def
MessageHandler(message, data):
if
message[
"type"
]
=
=
"send"
:
global
result
global
received
result
=
message[
"payload"
]
received
=
True
else
:
print
(message)
def
GeneratePossibilities(
dict
, count, repetitive
=
False
):
if
repetitive
and
(count >
1
):
src_dict
=
dict
for
i
in
range
(count
-
1
):
dict
+
=
src_dict
return
permutations(
dict
, count)
device
=
frida.get_device_manager().add_remote_device(
"192.168.1.5:8888"
)
pid
=
device.spawn(
"com.gdufs.xman"
)
session
=
device.attach(pid)
with
open
(
"index.js"
) as file_descriptor:
script
=
session.create_script(file_descriptor.read(), runtime
=
"v8"
)
script.on(
"message"
, MessageHandler)
script.load()
time.sleep(
1
)
device.resume(pid)
goal_three_character_array
=
[
"EoP"
,
"AoY"
,
"62@"
,
"ElR"
]
goal_three_character_array_length
=
len
(goal_three_character_array)
goal_last_character
=
"D"
my_dict
=
"abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*()?_"
flag
=
[
'*'
]
*
13
possibilities
=
GeneratePossibilities(my_dict,
3
,
True
)
time.sleep(
1
)
time_begin
=
time.time()
script.exports.hook()
first_part_times
=
0
try_count
=
0
for
p
in
possibilities:
character1, character2, character3
=
p
try_str
=
character1
+
character2
+
character3
try_count
+
=
1
sys.stdout.write(
"[{}]Try_str: {}\r"
.
format
(try_count, "".join(try_str)))
sys.stdout.flush()
received
=
False
script.exports.invoke(try_str)
while
not
received:
pass
for
i
in
range
(goal_three_character_array_length):
if
result
=
=
goal_three_character_array[i]:
if
flag[i
*
3
]
=
=
"*"
:
first_part_times
+
=
1
flag[i
*
3
: i
*
3
+
3
]
=
character1, character2, character3
break
sys.stdout.write(
"[*] Flag: xman{{{}}} "
.
format
("".join(flag)))
sys.stdout.flush()
if
first_part_times
=
=
4
:
break
print
(
"\033c"
)
try_count
=
0
for
try_str
in
my_dict:
sys.stdout.write(
"[{}]Try_str: {}\r"
.
format
(try_count, "".join(try_str)))
script.exports.invoke(try_str)
if
result
=
=
goal_last_character:
flag[
12
]
=
try_str
break
sys.stdout.write(
"[*] Flag: xman{{{}}} "
.
format
("".join(flag)))
sys.stdout.flush()
print
(
"\033c"
)
print
(
"[*] Flag: xman{{{}}}"
.
format
("".join(flag)))
time_end
=
time.time()
cost_time
=
time_end
-
time_begin
print
(
" cost time: "
+
str
(cost_time
/
/
60
)
+
"min"
)