question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

angr cannot find the answer for fauxware written in c++

See original GitHub issue

Hi, I wrote a simplified version of fauxware both in C and in C++, which only checks a password. However angr was not able to find the password, SOSNEAKY, for the one written in c++. Is this because angr does not fully support stdlibc++ yet or I might be doing something wrong?

// fauxware2.c - A simplified fauxware written in C
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

char *sneaky = "SOSNEAKY";

int authenticate(char *password) {
	// evil back d00r
	if (strcmp(password, sneaky) == 0) 
		return 1;
	else
		return 0;
}

int accepted() {
	printf("Welcome to the admin console, trusted user!\n");
}

int rejected() {
	printf("Go away!");
	exit(1);
}

int main(int argc, char **argv) {
	char username[9];
	char password[9];
	int authed;

	username[8] = 0;
	password[8] = 0;

	printf("Username: \n");
	read(0, username, 8);
	printf("Password: \n");
	read(0, password, 8);

	authed = authenticate(password);
	if (authed) 
            accepted();
	else 
            rejected();
    return 0;
}

Here is the same version of fauxware written in c++.

// fauxware.cc - A simplified fauxware written in C++
#include <iostream>
#include <cstring>
#include <cstdlib>

std::string sneaky = "SOSNEAKY";

int authenticate(std::string username, std::string password) {
	// evil back d00r
	if (std::strcmp(password.c_str(), sneaky.c_str()) == 0) 
           return 1;
	else
	   return 0;
}

int accepted() {
	std::cout << "Welcome to the admin console, trusted user!\n";
}

int rejected() {
	std::cout << "Go away!";
	exit(1);
}

int main(int argc, char **argv) {
	std::string username;
	std::string password;
	int authed;

	std::cout<<"Username: \n";
        getline(std::cin, username);
	std::cout<<"Password: \n";
        getline(std::cin, password);

	authed = authenticate(username, password);
	if (authed) 
            accepted();
	else 
            rejected();

    return 0;
}

And I set auto_load_libs as True when loading a binary and used full_init_state instead of entry_state when initializing a state.

import angr

def fauxware(binpath):
    p = angr.Project(binpath, load_options={"auto_load_libs": True})

    simFile = angr.SimFile('/dev/stdin')
    state = p.factory.full_init_state(stdin=simFile)

    while True:
        succ = state.step()
        if len(succ.successors) == 2:
            break
        state = succ.successors[0]

    state1, state2 = succ.successors
    input_data = state1.posix.stdin.load(0, state.posix.stdin.size)
    print state1.solver.eval(input_data, cast_to=str)
    print state2.solver.eval(input_data, cast_to=str)

if __name__ == '__main__':
    fauxware('fauxware2')
    fauxware('fauxware_cc')

Note that both were compiled with gcc and ld.bfd in ELF executable for x86-64, and dynamically linked. Thanks!

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
ltfishcommented, Aug 7, 2018

angr does not have enough function summaries (SimProcedures) implemented for C++. We also did not spend enough time implementing and testing the support of C++ programs of angr.

0reactions
rhelmotcommented, Aug 7, 2018

I just pushed a fix for that bug, which had already been reported as #1167.

Yes, we will run initializers if you’re using a full_init_state.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Examples - angr Documentation
This is a basic script that explains how to use angr to symbolically execute a program and produce concrete input satisfying certain conditions....
Read more >
[angr] Inquiry on applying Angr to finding backdoor of some ...
Hello, I'm writing to get some information about Angr. First of all, ... python import angr import archinfo # Look at fauxware.c!
Read more >
SymEx#2: Working with angr - techlifecompilation
Not quite. See, in the fauxware.c code a file with the name of username is opened and its content (the user's password) is...
Read more >
Simple angr example not working
The [] indicates that it did not find any solution. Can anybody tell me what I did wrong? c · angr · Share....
Read more >
Angr - HackTricks
proj.loader.find_object_containing(0x400000)#Get object loaded in an address "<ELF Object fauxware, maps [0x400000:0x60105f]>" ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found