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
37 changes: 33 additions & 4 deletions lab8/solve.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,40 @@
#!/usr/bin/env python3

import angr,sys
import angr
import claripy
import sys

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

input_len = 8
input_chars = [claripy.BVS(f'input_{i}', 8) for i in range(input_len)]
input_expr = claripy.Concat(*input_chars)

state = project.factory.full_init_state(
args=['./chal'],
stdin=input_expr
)

for char in input_chars:
state.solver.add(char >= 0x20)
state.solver.add(char <= 0x7e)

simgr = project.factory.simulation_manager(state)

def is_successful(state):
return b'Correct! The flag is:' in state.posix.dumps(1)

# Explore paths
simgr.explore(find=is_successful)

if simgr.found:
found = simgr.found[0]
# Extract the concrete value of the symbolic input
solution = found.solver.eval(input_expr, cast_to=bytes)
sys.stdout.buffer.write(solution + b'\n')
else:
print("No solution found.")

if __name__ == '__main__':
main()