3 hours 41 minutes
Okay, so let's continue our discussion about obfuscation and learn about X or
another cipher that is similar to the Caesar cipher is X or
extra is a mathematical bit wise operation. And this means that in this case, instead of using a shift of letters like our Caesar cipher, we are using X or to modify bits.
Now the extra operation works by evaluating the operations of two sequences of bites and producing a third sequence
in third sequence. If both operations are the same, the result is zero.
Otherwise, the result is one
X or encoding works on this same principle by taking a static byte value and modifying each bite of the plain text by performing the mathematical operation with that value.
For instance, here we have the plain text message dog.
This message is encoded with a single X or bite of three F.
Here you can see the asking characters as well as their hex and binary equivalent on the top.
Then the X or operation is performed on each character using the bite three F.
The corresponding cipher text is displayed on the bottom after the operation is performed.
In this example, you can see that the cipher text contains characters outside of the simple character set of our Caesar cipher.
Instead, we can use any value of are asking table that we've seen in previous sessions
X or is implemented quite frequently because it's pretty simple, and it only requires one machine code to reverse it. To decode any cipher text encoded with X, or you simply repeat the function with the same key that you used to encode the plain text.
Although X or encoding has its advantages when it comes to speed efficiency, it does have its disadvantages. It's really easy to detect with a simple hex editor. Now here I've loaded a file in a tool I like to use. Called violence site. It's not only a hex editor, but also allows you to inspect P E sections as well as to run script right inside.
As you can see in the encoded file, you'll notice that the bites of the file have a very similar pattern. You could see that the X, or key, of 3/8 prevalent throughout the file.
This is because the X or scheme amusing is exploring no bites, thes air bites that have no value.
This demonstrates the weakness of a single by encoding. Despite this, however, malware authors have mitigated this issue by using a no preserving export scheme. This scheme looks for no bites within the file and simply skips them. And if the export scheme detects the key itself, it also skips the bite.
This makes X, or a little bit harder to detect.
because no preserving X or maybe harder to detect the question becomes, well, how do we analyze the files that have been encoded with thes schemes?
Well, because there's only 256 possible values for a character in a file, it's pretty easy to create a program that will try all of the possible 255 single by X or keys.
Luckily, there's a few tools out there that will do this for us that are used in the industry.
One of the most popular options is Zoar Search. This is a tool by DDR Stevens, which will use a brute forcing technique to determine the X, or key, used to encrypt the P E file.
Using this tool, you can look for a matching string like MZ or this program cannot be run in DOS mode in the decrypted content.
Another technique to identify X or encoding or X or including loops, is to load the binary in ida pro
here in our lab and using either pro, you can use the search functionality for all X or instructions
to perform this operation, load the binary and Ida pro and used the search menu and navigate to text.
Then you can enter X or in the search field and check the match all occurrences box in the results, you can see that it's very common to see X or operations. Where the operations are the same registers
thes air instructions used by the compiler to zero out the register value.
You can ignore these instructions, but to find the encoding you wanna look for X or operandi of a constant value or memory reference in our output, you wanna look for a reference similar to what we have here, where we are exploring three b by E a X.
Once you find the instruction you are interested in,
you can double click it, and it will bring you to that section of the program. As you can see this instruction is part of our X or encryption loop.
Okay, so now that we've looked at overcoming X or obfuscation techniques next, let's examine basis 64.