Retrieving the flag
Last updated
Last updated
From the dashboard page (/dashboard.php
), I tried executing a few common commands such as whoami
, id
, pwd
, etc.
It appears that the application only allows the ls
command. From the output, I noticed an interesting file: 188ade1.key
.
Visiting the URL at /188ade1.key
downloads a file with the content:
I developed a Python script for the testing. First, we will need to login using the login()
function. This ensures that we retrieve a new PHPSESSID
that is associated with the email. Secondly, a POST request will be send to the /execute_command.php
path with the command in the request body — for code execution.
The following Python script is just an outline, the respective variables will be different for each test. The final exploit script can be found below.
The JWT specification defines a signature algorithm called none
. This means that there is no signature for the JWT, allowing the payload to be modified without any signing keys.
Change the alg
value in the headers field in the script above to none:
Output from Python script:
Error message: Invalid token: Algorithm not supported
Default HMAC signing key (firebase/php-jwt)
However, from research, it appears that this package does not employ any default signing keys.
Utilizing hashcat, I attempted to brute force the key using two wordlists from Daniel Miessler's SecLists:
The brute force attempt failed, and I was unable to find the valid signing key.
Remove the jwt.encode()
line, and retrieve the token from the existing cookies instead. There are many ways to malform the signature. For this test, I decided to remove the last character from the token.
Output:
kid
header valueIn our application, a symmetric key is used. Thus, the kid
value defines the path used to look up a value to be used as the signing key.
I attempted to change the kid
value to 188ade1.key
, and encode a new JWT with the content of that file.
With the command: cat /home/ubuntu/flag.txt
, I was able to retrieve the flag!
We have found the answer to the final question: "What is the content of the file /home/ubuntu/flag.txt?": THM{RUNANYCOMMAND1337}
.
FINAL Python script:
Upon analysis of the retrieved JWT token value (using ), I noticed the kid
field present in the headers. Moreover, there is a role
field in the payload, which controls the user role. The goal will be to change this value to a higher privilege user such as admin
.
Based on the testing guide, I decided to test the JWT based vulnerabilities.
From our previous enumeration, we have found out that the application uses firebase/php-jwt v6.10.0
(refer to ).
a)
b)