This tutorial gradually demonstrates BinCAT features, by analyzing a provided keygen-me-style program, which takes a few arguments as command-line parameters, then generates a hash depending on these parameters, and compares it to an expected license value.
This program expects a few arguments:
$ ./get_key_x86
Usage: ./get_key company department name licence
It returns an error message if an incorrect license key is entered:
$ ./get_key_x86 company department name wrong_serial
Licence=>[025E60CB08F00A1A23F236CC78FC819CE6590DD7]
Invalid serial wrong_serial
The program indicates if the correct license key is entered:
$ ./get_key_x86 company department name 025E60CB08F00A1A23F236CC78FC819CE6590DD7
Licence=>[025E60CB08F00A1A23F236CC78FC819CE6590DD7]
Thank you for registering !
- BinCAT has to be installed first (see README)
- Download one of the executables from this repository.
This tutorial relates to the
get_key_x86
binary, targetting
the x86
CPU architecture.
Binaries and configuration files are also provided for the following architectures:
armv7
: binary, configurationarmv8
: binary, configuration
- Load the BinCAT plugin by using the Ctrl + Shift + b shortcut
- Open the
get_key_x86
executable in IDA - From the IDA View-A view, go to address
0x93B
using the g shortcut - Focus the BinCAT Configuration pane
- Click
<-- Current
to define the start address - Ensure that the Analyzer configuration dropdown is set to (new)
- Check the Save configuration to IDB option
- Click the Edit... button
- Paste the following lines at the end of the
[state]
section, overwriting the existing stack initialization (stack[0x1000*8192]...
). This defines a value forargc
, creates 5 pointers to strings, and initializes 5 null-terminated strings, and also initialized a stack to TOP (unknown value)
stack[0x1000*4099] = |00|?0xFF
stack[0x2004] = 5
stack[0x2008] = 0x200000
mem[0x200000] = 0x300100
mem[0x200004] = 0x300140
mem[0x200008] = 0x300180
mem[0x20000C] = 0x3001C0
mem[0x200010] = 0x300200
mem[0x300100] = |6c6f6c3300|
mem[0x300140] = |636f6d70616e7900|
mem[0x300180] = |64657000|
mem[0x3001C0] = |6c6f6c3100|
mem[0x300200] = |6c6f6c2100|
- Click Save to close the configuration edit dialogue
- Click Save to save the configuration to the IDB
- Enter a name under which this configuration should be saved
- Click Start
- Notice that after a few seconds, the analysis has finished running, and the background for some of the instructions in the IDA View-A view has become gray
- Switch to the BinCAT registers view.
- Go to address
0x807
using the g shortcut. This instruction is located directly before a call to_sprintf(buffer, "Company = %s\n");
. Observe the value of theesp
register in the BinCAT Registers view (it should be0x1D50
). Open the BinCAT Memory view at this address, to observe the contents of thebuffer
pointer (char *
) wheresprintf
results will be output (the value should be0x1DEC
) - Advance to the next instruction at address
0x80C
, and observe the value of thebuffer
that has been formatted bysprintf
at address0x1DEC
- Hover your mouse over addresses
0x1D50
,0x1D54
,0x1D58
in the stack, and observe the inferred types for the call tosprintf
- Go to address
0xA93
, which contains a call to a location that is stored on the stack. Notice that IDA cannot resolve the destination address. In the BinCAT Registers view, use the goto next node (1) drop down menu to jump to the destination
This tutorial shows how to taint a register, and observe taint propagation.
- Go back to address
0x93B
- From the BinCAT Memory view, section
global
, override the value of every byte at addresses0x300140
-0x300147
which contains the null-terminatedcompany
string (see section Override taint of the manual), and set it to0xFF
. Re-run the analysis. - Advance to the next instruction at address
0x93F
, and observe that this memory range is indeed tainted: both the ASCII and hexadecimal representations of this string are displayed as green text - In the IDA View-A view, notice that some instructions are displayed against a green background, since they manipulate tainted data
- Go to address
0x9E6
(push eax
). Observe thateax
is partially tainted - Advance to the next instruction at address
0x9E7
. Notice thateax
has been pushed to the stack, where its taint and value have been copied
- Use the tainting feature to show that the result of the CRC computation on
the
department
argument does not influence the computed license key