Base64 - Algoritmo

PM_31_2COLBYN_CLAVES

The Internet is an unsafe place. People are afraid of being ā€œhackedā€ or having their access credentials stolen to their social media accounts like Instagram, Facebook or payment management platforms like PayPal. There are more and more victims of cyber attacks and, at the same time, more sophisticated ones. As a result, methods have been created to prevent the ā€œlegibleā€ display of confidential information when it is stolen, or at least very difficult to decipher.

Cryptography, a method that has been used since the 5th century BC to hide information, and which is still used today to hide messages, passwords, etc., there are many ways to hide something, some more complex than others, but all with the same purpose of ā€œhidingā€, these ways are based on a mathematical operation, and the more difficult this is, the more efficient it will be and the more complex it will be to decipher.

In this article I will explain what is and how the Base64 encoding algorithm works. This is a numeric system that needs 64 characters to encode any string, converting binary data into ASCII characters. It is mainly used to share binaries using protocols such as HTTP or MIME for the exchange of different types of data files on the Internet.

Uses of base64 in hacking

Base64 is widely used in computer security, whether in Cryptography or hacking itself, it can be used to encode a Reverse Shell, share binary data, exploit different vulnerabilities in systems, to bypass Firewalls and for many more things.

Codingā€¦

We are going to encode the word ā€œTESTā€, all in uppercase, the first thing is to pass these 4 bytes == 32 bits in 4 groups of 8 bits each.

The next step is to make groups of 6 bits from the corresponding 32 bits.

Since there were 2 bits left, we added 4 bits of zeros to complete the last group to 6 bits.

In this case the last one was left with 6 bits of zeros, but this does not have to be the case.

Next, we add 2 bits of zeros in front of each group of 6 bits.

Now we have 6 groups of 8 bits each, we convert each group by its decimal value.

Once this is done, we convert each value to its corresponding ASCII character index. You can do this from here Base64 index table.

And we would have our ā€œTESTā€ string encoded in Base64.

Decodingā€¦

To decode it, you basically have to do the reverse process, if the text string contains lowercase letters, the result may have lowercase letters, this is an example of decoding the word ā€œCAsAā€ in uppercase and lowercase letters and this is its hash Q0FzQQ== in base64.

The first thing to do now is to find the index of each byte in the hash.

minusucula(1)

Once done, we look for the corresponding binaries in the table, Binaries and ASCII.

You can convert the indices directly to binary and thus you do not need to subtract 2 bits at the beginning of each block of 8 bits.

Copia de minusucula(1)

Now we subtract 2 bits from the beginning.

Lowercase(2)(1)

We subtract 4 bits from the end and create groups of 8 bits.

Copia de minusucula(3)(1)

And finally we convert each 8-bit block to its corresponding character.

Copia de minusucula(4)(1)

Leave a comment