|
| 1 | +Ftrace V0.2 elfmaster [at] zoho.com |
| 2 | + |
| 3 | +DESCRIPTION: |
| 4 | + |
| 5 | +ftrace is a reverse engineering tool designed to help map out the execution flow |
| 6 | +of ELF executables (32bit and 64bit). Instead of printing system calls or library |
| 7 | +function calls, it prints out the local function calls as they are happening, |
| 8 | +and attempts to retrieve the function arguments and determine whether they are |
| 9 | +immediate or pointer type. As of version 0.2, function arguments are only shown |
| 10 | +for 64bit executables. This program is useful when wanting to see the function flow of |
| 11 | +a given executable during runtime without having to set incremental breakpoints |
| 12 | +and backtraces in a debugger like gdb. Ftrace relies on symbols for seeing a functions |
| 13 | +actual name, but the -S option will show function calls for functions without |
| 14 | +symbols as well, displaying them as sub_<addr>. As of v0.2, complete control flow |
| 15 | +-C feature was added which gives control flow information beyond just call instructions, |
| 16 | +moving into other branch instructions. Only branch <imm> instructions are currently |
| 17 | +supported, but will be adding disassembly of branch *<reg> soon. |
| 18 | + |
| 19 | + |
| 20 | +COMPILE: |
| 21 | + |
| 22 | +gcc ftrace.c -o ftrace |
| 23 | + |
| 24 | +USAGE: |
| 25 | + |
| 26 | +ftrace [-p <pid>] [-Stsve] <prog> <args> |
| 27 | + |
| 28 | +ARCHITECTURE: |
| 29 | + |
| 30 | +For 32bit executables set FTRACE_ARCH=32, it defaults to 64. |
| 31 | + |
| 32 | + |
| 33 | +OPTIONS: |
| 34 | + |
| 35 | +[-v] Verbose output, print symbol table info etc. |
| 36 | + |
| 37 | +[-p] This option is used to attach to an existing process ID. |
| 38 | + |
| 39 | +[-s] This option will show strings as they are passed through functions (As best it knows how) |
| 40 | + |
| 41 | +[-e] This will show certain ELF info such as symbols, and lists the shared library deps. |
| 42 | + |
| 43 | +[-t] Type detection will guess what pointer type a function argument is, if it is a pointer. |
| 44 | +It will detect pointers that are within the range of the text segment, data segment, heap and the stack. |
| 45 | + |
| 46 | +[-S] Show function calls that don't have a matching symbol (For stripped binaries) |
| 47 | + |
| 48 | +[-C] Complete control flow analysis (branch instructions other than call) |
| 49 | + |
| 50 | +EXAMPLE: |
| 51 | + |
| 52 | + |
| 53 | +elfmaster@Ox31337:~/code/ftrace/ftrace$ ./ftrace -Cs test |
| 54 | + |
| 55 | +[+] Function tracing begins here: |
| 56 | +PLT_call@0x400520:__libc_start_main() |
| 57 | +(CONTROL FLOW CHANGE [jmp]): Jump from .plt 0x40052b into .plt 0x4004d0 |
| 58 | +LOCAL_call@0x4004b0:_init() |
| 59 | +(CONTROL FLOW CHANGE [jz]): Jump from .init 0x4004be into .init 0x4004c5 |
| 60 | +(RETURN VALUE) LOCAL_call@0x4004b0: _init() = 0 |
| 61 | +(CONTROL FLOW CHANGE [jz]): Jump from .text 0x400608 into .text 0x400625 |
| 62 | +LOCAL_call@0x400692:b(0x1,0x2,0x3) |
| 63 | +PLT_call@0x400510:printf("%d, %d, %d\n") |
| 64 | +(CONTROL FLOW CHANGE [jmp]): Jump from .plt 0x40051b into .plt 0x4004d0 |
| 65 | +1, 2, 3 |
| 66 | +(RETURN VALUE) PLT_call@0x400510: printf("%d, %d, %d\n") = 8 |
| 67 | +(RETURN VALUE) LOCAL_call@0x400692: b(0x1,0x2,0x3) = a |
| 68 | +LOCAL_call@0x400646:func1("Hello",0xa) |
| 69 | +PLT_call@0x4004e0:strcpy() |
| 70 | +(CONTROL FLOW CHANGE [jmp]): Jump from .plt 0x4004eb into .plt 0x4004d0 |
| 71 | +(RETURN VALUE) PLT_call@0x4004e0: strcpy() = 7fffae340330 |
| 72 | +(CONTROL FLOW CHANGE [jz]): Jump from .text 0x400689 into .text 0x400690 |
| 73 | +(RETURN VALUE) LOCAL_call@0x400646: func1("Hello",0xa) = ff |
| 74 | +LOCAL_call@0x40062c:func2(0x4007e4) |
| 75 | +PLT_call@0x4004f0:puts() |
| 76 | +(CONTROL FLOW CHANGE [jmp]): Jump from .plt 0x4004fb into .plt 0x4004d0 |
| 77 | +stack string |
| 78 | +(RETURN VALUE) PLT_call@0x4004f0: puts() = d |
| 79 | +(RETURN VALUE) LOCAL_call@0x40062c: func2(0x4007e4) = d |
| 80 | +(CONTROL FLOW CHANGE [jz]): Jump from .text 0x400735 into .text 0x40073c |
| 81 | +LOCAL_call@0x400570:deregister_tm_clones() |
| 82 | +(RETURN VALUE) LOCAL_call@0x400570: deregister_tm_clones() = 7 |
| 83 | + |
| 84 | + |
| 85 | + |
| 86 | +BUGS: |
| 87 | + |
| 88 | +* Semi Rare EIO ptrace error (In progress to fix) |
| 89 | +* Memory leak with -s (In progress to fix) |
| 90 | + |
| 91 | +FUTURE: |
| 92 | + |
| 93 | +* Add support for function arguments on 32bit |
| 94 | +* Add support for following fork'd children of target process |
| 95 | +* Extend heuristics of 64bit procedure prologue calling convention for function args. |
| 96 | +* Add dwarf2 support for .debug section to get function prototype info |
| 97 | +* Port to FreeBSD |
| 98 | +* Add support for indirect calls, jmps. |
| 99 | + |
0 commit comments