8

Text strings are usually easily read in a binary file using any editor that supports ASCII encoding of hexadecimal values. These text snippets can be easily studied and altered by a reverse engineer.

What options does a developer have to encrypt these text snippets, and decrypt them, in runtime ?

8

Some options which may or may not be applicable depending on your needs:

  1. Avoid using strings to leak out interesting information when possible. For example if you are using strings to display error information or logging information, this can give any reverse engineer valuable details as to what might be going on in your application. Instead replace these strings with numerical error codes.

  2. Obfuscate all strings with some kind of symmetric algorithm like a simple XOR routine, or a crypto algorithm like AES. This will prevent the string from being discovered during a casual examination of your binary. I say 'obfuscate' as you will presumably be storing the crypto/xor key in your binary. Any reverse engineer who tries a little harder will surely recover the obfuscated strings.

  3. Encrypt all strings (make all the strings get linked into a separate section in your executable and encrypt this section) and store the decryption key outside of your binary. You could store the key remotely and restrict access server side where possible. So if a reverse engineer does get your binary they may not be able to access the key. The decryption key could also be generated dynamically on the users computer based off several predictable factors known about that users machine, essentially only allowing the encrypted data to be decrypted when run on this specific machine (or type of machine). This technique has been used by government malware to encrypt payloads for specific targets (If I can remember the link to the paper I read this in I will update answer).

  4. Get Creative, Store all strings in a foreign language and then at run time use an online translation service to translate the string back to your expected native language. This is of course not very practical.

Of course if your strings do get decoded/decrypted at run time then a reverse engineer could just dump the process from memory in order to see the strings. For this reason it may be best to decode/decrypt individual strings only when needed (possibly storing the decoded string in a temporary location and zeroing it after use).

  • 1
    See this stackoverflow question for techniques that protect unencrypted strings from being dumped from memory. – amccormack Mar 28 '13 at 18:03
  • 4
    +1 for "get creative." The best way to thwart attempts to understand your program is to use techniques not documented in online Q&A sites... – Daniel W. Steinbrook Mar 29 '13 at 2:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.