Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions lab8/solve.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,39 @@
#!/usr/bin/env python3

import angr,sys
import angr
import claripy
import sys

angr.loggers.disable_root_logger()

def is_flag_found(state):
output = state.posix.dumps(1)
return b"flag" in output

def main():
secret_key = b""
sys.stdout.buffer.write(secret_key)
project = angr.Project("./chal", auto_load_libs=False)

sym_chars = [claripy.BVS(f'byte_{i}', 8) for i in range(8)]
sym_input = claripy.Concat(*sym_chars)

state = project.factory.full_init_state(
stdin = angr.SimFileStream(name='stdin', content=sym_input, has_end=True)
)


simgr = project.factory.simgr(state)

simgr.explore(
find = lambda s:b"Correct!" in s.posix.dumps(1)
)

if simgr.found:
found = simgr.found[0]
secret_key = found.solver.eval(sym_input, cast_to=bytes)
sys.stdout.buffer.write(secret_key)
else:
print("No solution found!")
sys.exit(1)


if __name__ == '__main__':
Expand Down
Loading