Level 10 - Level 11
Last updated
Last updated
This time we have got cookies that are encrypted with XOR scheme.
The source code had the php logic that performed the XOR encryption.
Let's first breakdown, how the default cookie data is encrypted:
The data is first converted to json format.
Next the data is encrypted using the XOR encryption by passing it to the xor_encrypt
function.
Finally the encrypted data is encoded with base64 scheme.
Now lets take a look in to the XOR Cipher:
According to XOR Cipher:
data ( XOR ) key -> encrypted_data
encrypted_data ( XOR ) key -> data
data ( XOR ) encrypted_data -> key
If the length of the key is less than the length of the data, the key is repeatedly used to encrypt the data.
From the above conclusions, since we know the default data, which is encrypted as cookie, and also we have the encrypted data ( the actual cookie ), we can get the key by performing XOR operation between them. Let's try this.
We can get the default data from the source code.
The data given in the source code has to be converted to JSON format:
Next, we can get the cookie from the browser dev tools application tab:
Now we have got all the necessary data. The following php code utilizes the xor_encrypt
function that we got from the source code to perform the XOR operation on the given data.
From the output of the above code, we can see that the string KNHL
is repeated again and again, which shows that the key is KNHL
, since the length of the key is less than the length of the data, the key is repeatedly used.
Now we got the key. According to the source code, the password is shown if the value of showpassword
is equal to yes
.
So, let's create a cookie with the value of showpassword
as yes
. The following code encrypts the given data using XOR encryption, encodes the result with base64 scheme and returns the cookie.
Now we got the modified cookie, its time to grab the password. Update the cookie in the browser dev tools application tab and refresh the page.