A Tool for the Symbolic Execution of Linux Binaries - PySymemu (Slides)
A Tool for the Symbolic Execution of Linux Binaries - PySymemu (Slides)
Symbolic Execution
of Linux binaries
About Symbolic Execution
● Dynamically explore all program branches.
int main( ) {
int val;
read(STDIN, &val, sizeof(val) );
if ( val > 0 )
if ( val < 100 )
do_something( );
else
do_something_else( );
}
This is used for:
● Test generation and bug hunting.
● Several implementations:
○ SymDroid, Cloud9, Pex, jCUTE, Java PathFinder,
KLEE, s2e, fuzzball, mayhem, cbass
@instruction
def DEC(cpu, dest):
res = dest.write( dest.read() - 1 )
#Affected Flags o..szapc
cpu.calculateFlags('DEC', dest.size, res)
Memory
class Memory:
def mprotect(self, start, size, perms): …
def munmap(self, start, size): …
def mmap(self, addr, size, perms): …
def putchar(self, addr, data): …
def getchar(self, addr): …
Operating System Model (Linux)
class Linux:
def exe(self, filename, argv=[], envp=[]):…
def syscall(self, cpu):…
solver = Solver()
mem = SMemory(solver, bits, 12 )
cpu = Cpu(mem, arch )
linux = SLinux(solver, [cpu], mem, ... )
linux.exe(“./my_test”, argv=[], env=[])
The glue: Basic analysis loop
states = [‘init.pkl’]
while len(states) > 0 :
linux = load(state.pop())
while linux.running:
linux.execute()
if isinstance( linux.cpu.PC, Symbol):
vals = solver.getallvalues(linux.
cpu.PC)
-- generate states for each value --
break
Micro demo
python system.py -h
usage: system.py [-h] [-sym SYM] [-stdin STDIN]
[-stdout STDOUT]
[-stderr STDERR] [-env ENV]
PROGRAM ...
stdin:
PDF-1.2++++++++++++++++++++++++++++++
Symbolic inputs.
We need to mark whic part of the environment
is symbolic:
● STDIN: a file partially symbolic. Symbols
marked with “+”
● STDOUT and STDERR are placeholders.
● ARGV and ENVP can be symbolic
A toy example
Contacto:
[email protected]