Skip to content

Commit 835b3f6

Browse files
authored
Merge pull request #564 from bruce6005/lab8
[LAB8] 3135553034
2 parents edfae6d + 3aa9318 commit 835b3f6

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

lab2/main_test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,9 @@ test('Application: notifySelected()', () => {
9292
mockWrite.mock.restore();
9393
mockSend.mock.restore();
9494
});
95-
=======
9695
const { Application, MailSystem } = require('./main');
9796

9897
// TODO: write your tests here
9998
// Remember to use Stub, Mock, and Spy when necessary
99+
100+
const { Application, MailSystem } = require('./main');

lab8/solve.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,34 @@
11
#!/usr/bin/env python3
22

3-
import angr,sys
3+
import angr
4+
import claripy
5+
import sys
46

5-
def main():
6-
secret_key = b""
7-
sys.stdout.buffer.write(secret_key)
7+
def solve_binary(binary_path, input_len=8, success_msg=b"Correct!"):
8+
proj = angr.Project(binary_path, auto_load_libs=False)
9+
10+
user_input = claripy.BVS("user_input", input_len * 8)
11+
state = proj.factory.full_init_state(stdin=user_input)
12+
13+
simgr = proj.factory.simulation_manager(state)
14+
15+
def is_successful(s):
16+
output = s.posix.dumps(sys.stdout.fileno())
17+
return success_msg in output
818

19+
simgr.explore(find=is_successful)
20+
21+
if simgr.found:
22+
solution_state = simgr.found[0]
23+
result = solution_state.solver.eval(user_input, cast_to=bytes)
24+
return result[:input_len]
25+
else:
26+
return b"[!] Not found\n"
27+
28+
def main():
29+
binary = "./chal"
30+
flag = solve_binary(binary)
31+
sys.stdout.buffer.write(flag)
932

10-
if __name__ == '__main__':
33+
if __name__ == "__main__":
1134
main()

0 commit comments

Comments
 (0)