I create the following c program as a proof of concept. When I try to analyze it with anger it never finishes.
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
char *secret = "password";
int compare(char *string)
{
int i, c=0;
for (i=0; i< strlen(secret); i++)
{
if (string[i] == secret[i])
c++;
}
if (c == 8)
printf("You won");
return 0;
}
int main(int argc, char **argv)
{
char input[50];
scanf("%s", input);
compare(input);
return EXIT_SUCCESS;
}
The script is the following:
#!/usr/bin/env python
import angr
import sys
import logging
import claripy
FIND = 0x00000000000011dd
LEN = 8
def basic_symbolic_execution():
p = angr.Project('test', load_options={'auto_load_libs':False})
flag = claripy.BVS('flag', LEN * 8)
st = p.factory.entry_state(
stdin=flag,
)
sm = p.factory.simulation_manager(st)
sm.explore(find=FIND, num_find=1)
print("Found solution")
out = b''
for pp in sm.deadended:
out = pp.posix.dumps(1)
print(out)
import IPython; IPython.embed()
def test():
r = basic_symbolic_execution()
if __name__ == '__main__':
sys.stdout.buffer.write(basic_symbolic_execution())
I have also tried to use explore on the address of c++ 8 times and then checking the stdin and it finishes but the result is all zeros. I was wondering if any of you have faced something similar and what your solutions were.