21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

When this program is compiled with TEST_BUILD defined, the resulting binary will<br />

print the CRC32 computed for the function test_routine( ). If the computed CRC32<br />

is 0xFFF7FB7C, the following table indices will represent valid function pointers:<br />

b1[12], b2[7], b3[11], b4[15], b5[7], b6[15], b7[15], b8[15]. Each of these contains a<br />

pointer to the function that will process the next nibble in the checksum, except for<br />

b8[15], which contains a pointer to the function that is called when the checksum<br />

has proven valid. The tables in the source can now be rewritten to reflect these correct<br />

values:<br />

crc_check_fn b1[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, crc_nib2, 0, 0, 0 },<br />

b2[16] = { 0, 0, 0, 0, 0, 0, 0, crc_nib3, 0, 0, 0, 0, 0, 0, 0, 0 },<br />

b3[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, crc_nib4, 0, 0, 0, 0 },<br />

b4[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, crc_nib5 },<br />

b5[16] = { 0, 0, 0, 0, 0, 0, 0, crc_nib6, 0, 0, 0, 0, 0, 0, 0, 0 },<br />

b6[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, crc_nib7 },<br />

b7[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, crc_nib8 },<br />

b8[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, crc_good };<br />

Obviously, the NULL bytes will have to be replaced with other values to disguise the<br />

fact that they are invalid entries. They can be replaced with pointers to functions that<br />

handle incorrect checksums, or they can be filled with garbage values to make the<br />

program unstable. For example:<br />

crc_check_fn b8[16] = { crc_good - 64, crc_good - 60, crc_good - 56, crc_good - 52,<br />

crc_good - 48, crc_good - 44, crc_good - 40, crc_good - 36,<br />

crc_good - 32, crc_good - 28, crc_good - 24, crc_good - 20,<br />

crc_good - 16, crc_good - 12, crc_good - 8, crc_good - 4,<br />

crc_good };<br />

In this table, the use of incrementally increasing values causes the table to appear to<br />

be valid data, as opposed to addresses in the code segment. Note that you can use<br />

the techniques for disguising function pointers described in Recipe 12.9 so that<br />

casual scans through the data segment do not reveal this to be a table of function<br />

pointers.<br />

See Also<br />

Recipe 12.9<br />

12.3 Obfuscating Code<br />

<strong>Problem</strong><br />

Most C programs use common programming idioms based on C statements, default<br />

data types, and function invocation/return conventions based on the C standard<br />

library. Those familiar with C and how it is compiled to assembly language can easily<br />

identify these idioms in compiled binary code.<br />

658 | Chapter 12: Anti-Tampering<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!