Finding hidden strings like a pro
Every single program uses string to store file paths, labels, prompt text. But not everyone knows that plain text strings can be easily obtained with a debugger. Some programs even store passwords or any other important information in plain text strings. In this blog post I will go over the most popular ways of hiding/encrypting strings in programs.
Passwords should newer be stored as plain text (but we will do it anyways for demonstration purposes)! Better thing to do is to store a hash of the password and compare hashes.
First, let's demonstrate with an example what I mean by storing plain text strings:
Passwords should newer be stored as plain text (but we will do it anyways for demonstration purposes)! Better thing to do is to store a hash of the password and compare hashes.
First, let's demonstrate with an example what I mean by storing plain text strings:
Now, let's look at this program with the debugger. By searching for all referenced strings in the program we can easily discover what the password is, no need for advanced techniques:
Now, let's look at something more interesting. In this case we have an alphabet (char array), where we have defined our char set. When it comes to checking the string - we compose it on the fly (*cough* hard code), thus making it a little less obvious.
Now, instead of looking for the entire string containing a password we just need to look at the first character of each string.
Of course, we can make it better by having multiple char array, each storing a word that start's with the character we need, so that instead of displaying gibberish it would display real words. We could also define alphabet as an integer array to hide it. Nothing is good enough yet, moving on.
Next up is hard coding encrypted strings and decrypting them as needed.
The solution is obvious here: we can set a breakpoint right after the decryption function call and then we can see the decrypted sting.
The main issue we encounter is that the person debugging our program when seeing a function call to the 'strcmp' will know that something is up. Our best bet would be to make it less obvious where string comparison/output/input in code is happening. Lucky for us, there is nothing that can't be reverse engineered, all these techniques will make it harder to get to the plain text, but not impossible. Considering everything above said, here is a very good attempt at hiding intent of our code:
If we look at the disassembled code, 'strcmp' is nowhere to be found.
After looking at the 'sub_416930' function we could still tell what the password is, but it's not in plain text.
Hiding other strings and functions can make it even harder for the person debugging the program to discover the password, but like I said earlies there is nothing that can't be reverse engineered. If you know other techniques used to hide string, feel free to send me a message or post a comment, I will be glad to check it out!
References and useful links:
Cool
ReplyDeleteX2
Delete