All Projects → nh2 → hatrace

nh2 / hatrace

Licence: other
scriptable strace

Programming Languages

haskell
3896 projects
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to hatrace

tracecode-toolkit-strace
Trace software components, packages and files between Development/Source and Deployment/Distribution/Binaries codebases - strace build analysis
Stars: ✭ 21 (-82.05%)
Mutual labels:  strace
pinktrace
Pink's Tracing Library
Stars: ✭ 20 (-82.91%)
Mutual labels:  strace
phuzz
Find exploitable PHP files by parameter fuzzing and function call tracing
Stars: ✭ 53 (-54.7%)
Mutual labels:  strace
b1m0-dbg
linux debugger
Stars: ✭ 11 (-90.6%)
Mutual labels:  strace
fptrace
Record process launches and files read and written by each process
Stars: ✭ 41 (-64.96%)
Mutual labels:  strace
ttycopy
A tool scanning other terminal.
Stars: ✭ 15 (-87.18%)
Mutual labels:  strace

CircleCI

hatrace - scripted strace

Includes:

  • hatrace executable similar to strace
  • Haskell library to write sophisticated scripts

Use cases

  • General
    • Get all syscalls in a list and process them programmatically.
    • Audit high-assurance software systems.
    • Debug difficult bugs that occur only in certain rare situations.
    • Change the results of system calls as seen by the traced program.
  • Bug reproducers
    • Demonstrate how a program fails when a given syscall returns certain data.
    • Kill your build tool at the 3rd write() syscall to an .o file, checking whether it will recover from that in the next run.
  • Testing
    • Write test suites that assert how your code uses system calls, for correctness or performance.
    • Mock syscalls to test how your program would behave in situations that are difficult to create in the real world, for example verifying fault-tolerance in specific scenarios
    • Implement anomaly test suites like sqlite does, exhaustively testing whether your program can recover from a crash in any syscall.
  • Fuzzing
    • Insert garbage data into the program by changing syscall results or directly changing its memory contents.
    • Speed up your fuzzing by having full insight into the fuzzed program's behaviour.
  • Adding features to existing programs
    • Add "magic" support for new file systems without modifying existing programs (like this paper shows).
    • Add logging capabilities to programs that were designed without.

Building / Installing

  • Clone: git clone --recursive https://github.com/nh2/hatrace && cd hatrace
  • After fetching new changes, update submodules with: git submodule init && git submodule update --init --recursive
  • Building for development:
    • With Stack: stack build or even better stack test
    • With Cabal: cabal build or even better cabal test
    • Use a recent version of these tools, e.g. at least Stack >= 2.
  • Installing:
    • With Stack: stack install
    • With Cabal: cabal install

Work in progress

This software is work in progress.

The hatrace executable is extremely basic and can't do much.

While syscall names are automatically generated, detail data needs to be implemented by hand and is done for only a few so far. Help to add more is appreciated.

However, the Haskell API to write scripts can already do a lot. Take a look at the test suite for examples.

TODO list for contributors

If you find any of the below topics interesting give it a shot! It is recommended to file an issue when picking up one of the tasks to coordinate and avoid doing duplicate work.

  • Implement all the syscalls
  • Remembering syscall arguments in a PID/TID map
  • Support for sysenter
  • reading tracee memory more efficiently (see how strace does it)
  • Helpers for modifying memory
  • One real-world example each for the use cases on Use cases above
  • hatrace executable features:
    • JSON output
    • Coloured output
    • Timing strace -ttt and -T
    • special run modes tailored to specific tasks (e.g. execve tree)
      • Show hanging syscalls
      • Filter away GHC's spammy output around sched_yield, futex and signals
  • Support for setting options (for example enabling/disabling tracing into subprocesses, like strace -f)
  • Equivalent to strace -y (tracking origin of file descriptors, printing paths)
  • Equivalent to strace -c (keeping counts, summary statistics)
  • Something similar to strace -y but telling which PID is which executable from /proc/PID/exe
  • Extraction of PTRACE_EVENT detail information (see section PTRACE_SETOPTIONS in man 2 ptrace)
  • Filtering based on string buffer contents
  • PID remapping (e.g. to a range starting from 0) for better diffability of the output of multiple runs
  • Handling of exit() of the direct child (grand-child daemonisation)
  • Don't die on peekBytes returning EIO when the tracee passes invalid memory to the kernel; instead, peek only what's possible and print some info. That makes it possible to correctly trace processes that rely on e.g. SIGSEGV handlers.
  • Re-using strace's test suite for per-syscall tests
  • other TODOs in the code
  • Use it to do specific investigations in other programs:
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].