21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Discussion<br />

The techniques for hiding strings presented in this recipe are intended<br />

to prevent their discovery from casual analysis, and should not be considered<br />

a secure way of hiding strings. In cases where a string must be<br />

hidden securely, you should treat the string as if it were a password,<br />

and use a strong encryption method.<br />

The purpose of obfuscating data is to mislead the observer in such a way that he may<br />

not even realize that the obfuscation has taken place. Calling an encryption routine is<br />

a more secure way to hide data, but it defeats the purpose of obfuscation as it makes<br />

obvious the fact that the data is both encrypted and important.<br />

An example of dynamically generating strings from a collection of substrings is presented<br />

below. In the example, the string “/etc/passwd” is created on the fly. A quick<br />

scan of the compiled version of the code will not reveal the string because the characters<br />

that compose it are stored out of order as separate strings. Routines like this one<br />

can be generated automatically by Perl or shell scripts as a separate C source code<br />

file, then linked in with rest of the program’s object files.<br />

#include <br />

#include <br />

char *get_filename(int n, char *buf, int buf_len) {<br />

int x;<br />

char *p;<br />

buf[0] = 0;<br />

p = &((char *)&n)[0];<br />

for (x = 0; x < 4; x++, p++) {<br />

switch (*p) {<br />

case 1:<br />

strncat(buf, "swd", buf_len - strlen(buf));<br />

break;<br />

case 2:<br />

strncat( buf, "no", buf_len - strlen(buf));<br />

break;<br />

case 3:<br />

strncat( buf, "/e", buf_len - strlen(buf));<br />

break;<br />

case 4:<br />

strncat( buf, "as", buf_len - strlen(buf));<br />

break;<br />

case 5:<br />

strncat( buf, "us", buf_len - strlen(buf));<br />

break;<br />

case 6:<br />

strncat( buf, "tc/p", buf_len - strlen(buf));<br />

break;<br />

case 7:<br />

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

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.<br />

Hiding Strings | 679

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

Saved successfully!

Ooh no, something went wrong!