ltrace and strace: Watching a Binary's Library and System Calls

Tool · Rev Eng

Before opening Ghidra on a crackme, try running it under ltrace. Many beginner reversing challenges compare your input against the correct password with strcmp or memcmp — and ltrace prints both arguments of that call as it happens.

ltrace: library calls

$ ltrace ./crackme
puts("Enter the password:")                  = 20
fgets("hello\n", 64, 0x7f...)              = 0x7ffc...
strcmp("hello", "s3cr3t_p4ss")              = -11
puts("Wrong!")                               = 7

The second argument to strcmp is the password. ltrace hooks calls into shared libraries like libc, so it works on any dynamically linked binary. Useful flags:

strace: system calls

$ strace ./mystery
openat(AT_FDCWD, "/tmp/.hidden_key", O_RDONLY) = -1 ENOENT (No such file or directory)
write(1, "Key file missing\n", 17)          = 17

strace shows every interaction between the program and the kernel: files opened, data read and written, network connections, child processes. It answers questions like "what file is it looking for?" or "where does it connect?" Add -f to follow child processes and -e trace=openat,read to filter.

When they don't work

Where they fit

ltrace and strace are the quickest form of dynamic analysis: no setup, no breakpoints, just run and read. Use them first; if they don't reveal the answer, move to GDB for stepping through the code or Ghidra to read it. As always, only run untrusted challenge binaries in a VM or container.

← Back to Blog