GithubHelp home page GithubHelp logo

usercorn's Introduction

usercorn

Build Status GoDoc Slack

Building

Usercorn depends on Go 1.6 or newer, as well as the latest unstable versions of Capstone, Unicorn, and Keystone.

make deps (requires cmake) will attempt to install all of the above dependencies into the source tree under deps/.

make will update Go packages and build usercorn

Example Commands

usercorn run bins/x86.linux.elf
usercorn run bins/x86_64.linux.elf
usercorn run bins/x86.darwin.macho
usercorn run bins/x86_64.darwin.macho
usercorn run bins/x86.linux.cgc
usercorn run bins/mipsel.linux.elf

usercorn run -trace bins/x86.linux.elf
usercorn run -trace -to trace.uc bins/x86.linux.elf
usercorn trace -pretty trace.uc
usercorn run -repl bins/x86.linux.elf

What.

  • Usercorn is an analysis and emulator framework, with a base similar to qemu-user.
  • It can run arbitrary binaries on a different host kernel, unlike qemu-user.
  • While recording full system state at every instruction.
  • to a serializable compact format capable of rewind and re-execution.
  • It's useful out of the box for debugging and dynamic analysis.
  • With an arch-neutral powerful lua-based scripting language and debugger.
  • It's also easy to extend and use to build your own tools.

Usercorn could be used to emulate 16-bit DOS, 32-bit and 64-bit ARM/MIPS/x86/SPARC binaries for Linux, Darwin, BSD, DECREE, and even operating systems like Redux.

Right now, x86_64 linux and DECREE are the best supported guests.

Why?

  • Usercorn aims to be a framework to simplify emulating and deeply hooking a userspace environment for many target architectures and kernel ABIs.
  • Debug stubborn binaries. I had a binary gdb refused to debug ("Program exited during startup."). No problem. Usercorn can single-step into the program for you.
  • Debug foreign architecture and OS binaries. You don't need a MIPS box. You don't need qemu-user. You don't even need Linux.
  • Write tools, like fuzzers, static analyzers, recompilers, memory and register analysis, overlay code coverage and machine state into IDA/Binary Ninja.
  • Selectively call functions from within a binary. Usercorn will map a binary and emulate the kernel for you.
  • Whatever you want. Open an issue if you have a cool debugging / reverse engineering idea I didn't think about - I may just implement it.

Caveats

  • Your userspace might be incredibly confusing to the target binary.
  • No API for memory mapped files yet (kinda, if mmap() currently gets a file descriptor argument it will manually copy the file into memory).
  • I only have maybe 20% of the posix syscalls implemented, which is enough to run basic binaries. Busybox works great.

See Also (credit: XKCD)

Universal converter

usercorn's People

Contributors

afrocheese avatar caesurus avatar ctfhacker avatar grazfather avatar lunixbochs avatar mmm-j avatar sjcappella avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

usercorn's Issues

add syscall hook function per-arch/os

hooking insn_x86_syscall doesn't make any sense on arm/mips/etc.

could probably just make this an init function and remove the syscall hooks at root level.

heuristic printf exploiter

identify stack variables pointing at the stack (or input/output buffer offset on the stack), automatically build a useful address chain for arbitrary memory control

ropwise disassembly

look for obvious rops in return (instructions that return to no call site)

Python: x86_64 darwin fails on exit

hello with printf: world
args (11):
01 @0x1000001 = "bins/x86_64.darwin.macho"
test: hi
strcmp: -11, 11, 01
file test 1: success

file test 2: success
success

Traceback (most recent call last):
File "_ctypes/callbacks.c", line 314, in 'calling callback function'
File "/usr/local/lib/python2.7/site-packages/unicorn/unicorn.py", line 249, in _hook_insn_syscall_cb
cb(self, data)
File "/Users/aegis/projects/usercorn/py/usercorn/cls.py", line 110, in hook_syscall
self.os.syscall(self.uc)
File "/Users/aegis/projects/usercorn/py/usercorn/arch/x64/darwin.py", line 26, in syscall
ret = syscalls.call(cls, SYSCALLS, num, lambda n: args[:n])
File "/Users/aegis/projects/usercorn/py/usercorn/syscalls.py", line 59, in call
return f(cls, *args) or 0
File "/Users/aegis/projects/usercorn/py/usercorn/syscalls.py", line 16, in write
return os.write(a1, cls.mem_read(a2, a3))
File "/usr/local/lib/python2.7/site-packages/unicorn/unicorn.py", line 189, in mem_read
data = ctypes.create_string_buffer(size)
File "/usr/local/Cellar/python/2.7.10_2/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ctypes/init.py", line 65, in create_string_buffer
buftype = c_char * init
ValueError: Array length must be >= 0, not -17958193

support dynamic linkers

  • if type == EXEC, it's a normal executable
  • if type == DYN, we mmap it somewhere
  • also PT_INTERP gets vm_mmap()'d after elf_map runs and maps the whole elf
  • so for exec'd linker, I need to start with DYN
  • for INTERP ld-linux, I need to map the elf, then load and map the interpreter
  • be careful to not map linker after the data segment so we can brk()

  • support linux auxv
  • support linux vdso
  • support osx auxv equivalent (not sure 100% how the ABI plays out yet but dyld source is short)
  • support osx commpage
  • branch protect master when this is done and switch dev to an unstable branch

"run until entry point"

invoke the interpreter to load dynamic libraries and stuff, then return or continue with hooks enabled at the real entry point

track valid addresses that have been loaded into registers

can also bound the addresses automatically based on increment vs store

array bound detection via accumulator too - if we're in a loop that's incrementing one or more memory addresses and affecting an accumulator in a proportional manner...

time traveling memory debugger

from a recorded trace, ability to select pages and slide across time - see register and memory state at specific time

annotate disassembler like ida with state of program at basic block entry, at register level, etc

"this instruction was hit 3000 times, with values X Y Z etc"

"this instruction touched these regions of memory [picture]" (with time slider to see when)

add ASLR mapping emulation flag

consider how different operating systems would map the binary
also look at literally copying offsets from /proc/self/maps

add gdb stub?

how do I do breakpoints? dump an architecture specific trap at the target location?

debug patching/tracing

run the program as normal, but trace specific memory access address(es), instructions

script a breakpoint and print buffers or registers at it, state diffing built in

automatic stacktrace

every time we enter a new block, check the stack pointer
we can tell if we did ret or call based on this

generate syscall lists

I shouldn't need to maintain these by hand

  • Linux/x86
  • Linux/x86_64
  • Linux/arm
  • Linux/mips
  • Linux/m68k
  • Linux/sparc
  • Darwin/x86
  • Darwin/arm

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.