Skip to content

Instantly share code, notes, and snippets.

@adambpa
Last active February 8, 2021 01:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adambpa/faea41332ee9afc08ddbf6da131c75a3 to your computer and use it in GitHub Desktop.
Save adambpa/faea41332ee9afc08ddbf6da131c75a3 to your computer and use it in GitHub Desktop.
Babymix.py
#!/usr/bin/env python3
import angr
import claripy
import time
def solve():
proj = angr.Project("./babymix",
main_opts = {"base_addr": 0},
auto_load_libs = False)
password_bytes = [claripy.BVS("byte_%d" % i, 8) for i in range(22)]
password_bytes_ast = claripy.Concat(*password_bytes + [claripy.BVV(b'\n')])
st = proj.factory.full_init_state(
args=['./babmix'],
add_options=angr.options.unicorn,
stdin=password_bytes_ast
)
for k in password_bytes:
st.solver.add(k < 0x7f)
st.solver.add(k > 0x20)
sm = proj.factory.simulation_manager(st)
sm.run()
out = b''
for pp in sm.deadended:
out = pp.posix.dumps(1)
if b'Correct!' in out:
out = pp.solver.eval(password_bytes_ast, cast_to=bytes).decode("utf-8", "ignore")
print(out)
return
if __name__ == "__main__":
before = time.time()
solve()
after = time.time()
print("Time elapsed: {}".format(after - before))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment