Skip to content

Commit bf25aa8

Browse files
s0cm0nkeygitbook-bot
authored andcommitted
GitBook: [#1315] No subject
1 parent efc3f1a commit bf25aa8

3 files changed

Lines changed: 73 additions & 72 deletions

File tree

‎SUMMARY.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
* [Insecure Direct Object Reference](web-app-hacking/attacks-and-vulnerabilities/insecure-direct-object-reference.md)
7171
* [SQL Injection](web-app-hacking/attacks-and-vulnerabilities/sql-injection/README.md)
7272
* [SQL Tips and Tricks](web-app-hacking/attacks-and-vulnerabilities/sql-injection/sql-tips-and-tricks.md)
73-
* [SQL Methodology](web-app-hacking/attacks-and-vulnerabilities/sql-injection/sql-methodology.md)
73+
* [SQL Basics](web-app-hacking/attacks-and-vulnerabilities/sql-injection/sql-methodology.md)
7474
* [Manual Injection Methodology](web-app-hacking/attacks-and-vulnerabilities/sql-injection/manual-injection-methodology.md)
7575
* [Web Cache Poisoning](web-app-hacking/attacks-and-vulnerabilities/web-cache-poisoning.md)
7676
* [Web Sockets](web-app-hacking/attacks-and-vulnerabilities/web-sockets.md)

‎web-app-hacking/attacks-and-vulnerabilities/http-host-header-attacks.md‎

Lines changed: 18 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,7 @@
22

33
## How it works
44

5-
* [https://portswigger.net/web-security/host-header](https://portswigger.net/web-security/host-header)
6-
* [https://www.intruder.io/research/practical-http-header-smuggling](https://www.intruder.io/research/practical-http-header-smuggling)
7-
8-
<details>
9-
10-
<summary>Basics</summary>
5+
### **Basics**
116

127
* The HTTP Host header is a mandatory request header as of HTTP/1.1. It specifies the domain name that the client wants to access
138
* The purpose of the HTTP Host header is to help identify which back-end component the client wants to communicate with. This can occur with a single server hosting multiple domains or when websites are hosted on distinct back-end servers, but all traffic between the client and servers is routed through an intermediary system. This could be a simple load balancer or a reverse proxy server of some kind.
@@ -19,13 +14,14 @@
1914
* &#x20;Routing-based SSRF
2015
* &#x20;Classic server-side vulnerabilities, such as SQL injection
2116

22-
</details>
17+
### **Reference**
2318

24-
## Recon and Identification
19+
* [https://portswigger.net/web-security/host-header](https://portswigger.net/web-security/host-header)
20+
* [https://www.intruder.io/research/practical-http-header-smuggling](https://www.intruder.io/research/practical-http-header-smuggling)
2521

26-
<details>
22+
## Recon and Identification
2723

28-
<summary>Give an arbitrary Host header and Check for flawed validation</summary>
24+
### Give an arbitrary Host header and Check for flawed validation
2925

3026
* &#x20;You should try to understand how the website parses the Host header. This can sometimes reveal loopholes that can be used to bypass the validation. For example, some parsing algorithms will omit the port from the Host header, meaning that only the domain name is validated. If you are also able to supply a non-numeric port, you can leave the domain name untouched to ensure that you reach the target application, while potentially injecting a payload via the port.
3127

@@ -40,13 +36,7 @@
4036
&#x20;`GET /example HTTP/1.1`\
4137
&#x20;`Host: hacked-subdomain.vulnerable-website.com`
4238

43-
44-
45-
</details>
46-
47-
<details>
48-
49-
<summary>Send ambiguous requests</summary>
39+
### Send ambiguous requests
5040

5141
* Inject duplicate headers
5242
* &#x20;`GET /example HTTP/1.1`\
@@ -58,11 +48,7 @@
5848
* Add line wrapping
5949
* Misc HTTP request smuggling techniques
6050

61-
</details>
62-
63-
<details>
64-
65-
<summary>Inject override headers</summary>
51+
### Inject override headers
6652

6753
* You can sometimes use `X-Forwarded-Host` to inject your malicious input while circumventing any validation on the Host header itself.
6854
* &#x20;`GET /example HTTP/1.1`\
@@ -74,85 +60,57 @@
7460
* &#x20;`X-HTTP-Host-Override`
7561
* &#x20;`Forwarded`
7662

77-
</details>
78-
7963
## **HTTP Header Attacks**
8064

8165
**\*\*\*** In Burp Suite, you can use the [Param Miner](https://portswigger.net/bappstore/17d2949a985c4b7ca092728dba871943) extension's "Guess headers" function to automatically probe for supported headers using its extensive built-in wordlist.\*\*\*
8266

83-
<details>
84-
85-
<summary>Password Reset poisoning</summary>
67+
### **Password Reset poisoning**
8668

87-
* [https://portswigger.net/web-security/host-header/exploiting/password-reset-poisoning](https://portswigger.net/web-security/host-header/exploiting/password-reset-poisoning)
8869
* Attack Process
8970
1. &#x20;The attacker obtains the victim's email address or username, as required, and submits a password reset request on their behalf. When submitting the form, they intercept the resulting HTTP request and modify the Host header so that it points to a domain that they control. For this example, we'll use `evil-user.net`.
9071
2. &#x20;The victim receives a genuine password reset email directly from the website. This seems to contain an ordinary link to reset their password and, crucially, contains a valid password reset token that is associated with their account. However, the domain name in the URL points to the attacker's server:\
9172
&#x20;`https://evil-user.net/reset?token=0a1b2c3d4e5f6g7h8i9j`
9273
3. &#x20;If the victim clicks this link (or it is fetched in some other way, for example, by an antivirus scanner) the password reset token will be delivered to the attacker's server.
9374
4. &#x20;The attacker can now visit the real URL for the vulnerable website and supply the victim's stolen token via the corresponding parameter. They will then be able to reset the user's password to whatever they like and subsequently log in to their account.
75+
* [https://portswigger.net/web-security/host-header/exploiting/password-reset-poisoning](https://portswigger.net/web-security/host-header/exploiting/password-reset-poisoning)
9476

77+
### **Web Cache Poisoning via Host Header**
9578

96-
97-
</details>
98-
99-
<details>
100-
101-
<summary>Web Cache Poisoning via Host Header</summary>
102-
103-
* To construct a web cache poisoning attack, you need to elicit a response from the server that reflects an injected payload. The challenge is to do this while preserving a cache key that will still be mapped to other users' requests. If successful, the next step is to get this malicious response cached. It will then be served to any users who attempt to visit the affected page.
79+
* &#x20;**** To construct a web cache poisoning attack, you need to elicit a response from the server that reflects an injected payload. The challenge is to do this while preserving a cache key that will still be mapped to other users' requests. If successful, the next step is to get this malicious response cached. It will then be served to any users who attempt to visit the affected page.
10480
* [https://portswigger.net/web-security/web-cache-poisoning](https://portswigger.net/web-security/web-cache-poisoning)
10581
* [https://portswigger.net/web-security/host-header/exploiting/lab-host-header-web-cache-poisoning-via-ambiguous-requests](https://portswigger.net/web-security/host-header/exploiting/lab-host-header-web-cache-poisoning-via-ambiguous-requests)
10682

107-
</details>
83+
### **Classic Server-Side Vulnerabilities** - SQL Injection via the Host Header
10884

109-
<details>
110-
111-
<summary>Accessing Restricted Functionality</summary>
85+
### **Accessing Restricted Functionality**
11286

11387
* Some websites' access control features make flawed assumptions that allow you to bypass these restrictions by making simple modifications to the Host header.
11488
* [https://portswigger.net/web-security/host-header/exploiting/lab-host-header-authentication-bypass](https://portswigger.net/web-security/host-header/exploiting/lab-host-header-authentication-bypass)
11589

116-
117-
118-
</details>
119-
120-
<details>
121-
122-
<summary>Accessing Internal Websites via Host Brute-Forcing</summary>
90+
### **Accessing Internal Websites via Host Brute-Forcing**
12391

12492
* &#x20;Companies sometimes make the mistake of hosting publicly accessible websites and private, internal sites on the same server. Servers typically have both a public and a private IP address. As the internal hostname may resolve to the private IP address, this scenario can't always be detected simply by looking at DNS records:
12593

12694
&#x20;`www.example.com: 12.34.56.78`\
12795
&#x20;`intranet.example.com: 10.0.0.132`
12896
* In some cases, the internal site might not even have a public DNS record associated with it. Nonetheless, an attacker can typically access any virtual host on any server that they have access to, provided they can guess the hostnames.
12997

130-
</details>
131-
132-
<details>
133-
134-
<summary>Routing Based SSRF</summary>
98+
### **Routing Based SSRF**
13599

136100
* It is possible to use the Host header to launch high-impact, routing-based SSRF attacks. These are sometimes known as "Host header SSRF attacks".
137101
* &#x20;You can use Burp Collaborator to help identify these vulnerabilities. If you supply the domain of your Collaborator server in the Host header, and subsequently receive a DNS lookup from the target server or another in-path system, this indicates that you may be able to route requests to arbitrary domains.
138102
* &#x20;Having confirmed that you can successfully manipulate an intermediary system to route your requests to an arbitrary public server, the next step is to see if you can exploit this behavior to access internal-only systems. To do this, you'll need to identify private IP addresses that are in use on the target's internal network. In addition to any IP addresses that are leaked by the application, you can also scan hostnames belonging to the company to see if any resolve to a private IP address. If all else fails, you can still identify valid IP addresses by simply brute-forcing standard private IP ranges, such as `192.168.0.0/16`.
139103
* [https://portswigger.net/web-security/host-header/exploiting/lab-host-header-routing-based-ssrf](https://portswigger.net/web-security/host-header/exploiting/lab-host-header-routing-based-ssrf)
140104
* [https://portswigger.net/web-security/host-header/exploiting/lab-host-header-ssrf-via-flawed-request-parsing](https://portswigger.net/web-security/host-header/exploiting/lab-host-header-ssrf-via-flawed-request-parsing)
141105

142-
</details>
143-
144-
<details>
106+
### **SSRF via Malformed Request Line**
145107

146-
<summary>SSRF via Malformed Request Line</summary>
147-
148-
* Custom proxies sometimes fail to validate the request line properly, which can allow you to supply unusual, malformed input with unfortunate results.
108+
* &#x20;Custom proxies sometimes fail to validate the request line properly, which can allow you to supply unusual, malformed input with unfortunate results.
149109
* &#x20;For example, a reverse proxy might take the path from the request line, prefix it with `http://backend-server`, and route the request to that upstream URL. This works fine if the path starts with a `/` character, but what if starts with an `@` character instead?
150110

151111
&#x20;`GET @private-intranet/example HTTP/1.1`
152112
* &#x20;The resulting upstream URL will be `http://backend-server@private-intranet/example`, which most HTTP libraries interpret as a request to access `private-intranet` with the username `backend-server`.
153113

154-
</details>
155-
156114
## **HTTP Header Attack Protection**
157115

158116
* **Protect absolute URLs -** When you have to use absolute URLs, you should require the current domain to be manually specified in a configuration file and refer to this value instead of the Host header. This approach would eliminate the threat of password reset poisoning, for example.

‎web-app-hacking/attacks-and-vulnerabilities/sql-injection/README.md‎

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
## Guides and Resources
44

5-
*
5+
{% tabs %}
6+
{% tab title="Guides" %}
67
* [https://www.sqlinjection.net/](https://www.sqlinjection.net/)
78
* [https://owasp.org/www-community/attacks/SQL\_Injection](https://owasp.org/www-community/attacks/SQL\_Injection)
89
* [https://owasp.org/www-community/Injection\_Flaws](https://owasp.org/www-community/Injection\_Flaws)
@@ -14,20 +15,28 @@
1415
* [https://pentestbook.six2dez.com/enumeration/web/sqli](https://pentestbook.six2dez.com/enumeration/web/sqli)
1516
* [https://github.com/kleiton0x00/Advanced-SQL-Injection-Cheatsheet](https://github.com/kleiton0x00/Advanced-SQL-Injection-Cheatsheet)
1617
* _SQL Injection Vulnerabilities - Bug Bounty Hunting Essentials, pg 29_
18+
{% endtab %}
1719

18-
### Payload Cheatsheets
19-
20+
{% tab title="Payload Cheatsheets" %}
2021
* [https://portswigger.net/web-security/sql-injection/cheat-sheet](https://portswigger.net/web-security/sql-injection/cheat-sheet)
2122
* [https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SQL%20Injection)
2223
* [https://github.com/payloadbox/sql-injection-payload-list/](https://github.com/payloadbox/sql-injection-payload-list/)
2324
* [https://websec.ca/kb/sql\_injection](https://websec.ca/kb/sql\_injection)
2425
* [http://pentestmonkey.net/category/cheat-sheet/sql-injection](http://pentestmonkey.net/category/cheat-sheet/sql-injection)
2526
* [https://www.codecademy.com/articles/sql-commands](https://www.codecademy.com/articles/sql-commands)
27+
{% endtab %}
28+
{% endtabs %}
29+
30+
{% content-ref url="sql-tips-and-tricks.md" %}
31+
[sql-tips-and-tricks.md](sql-tips-and-tricks.md)
32+
{% endcontent-ref %}
2633

2734
## ****[**SQLmap**](https://github.com/sqlmapproject/sqlmap) **** &#x20;
2835

2936
SQL Injection tool that can spawn a meterpreter or VNC session back to attacker. Can return a decent number of false positives. Always verify. If you do not specify a value, SQLmap will attempt all by default
3037

38+
{% tabs %}
39+
{% tab title="Guides and Resources" %}
3140
* [SQLMate](https://github.com/s0md3v/sqlmate) - Companion tool for SQLMap
3241
* &#x20;Maps out and locates admin panel
3342
* Query dorking for finding targets
@@ -39,9 +48,9 @@ SQL Injection tool that can spawn a meterpreter or VNC session back to attacker.
3948
* [https://tryhackme.com/room/sqlmap](https://tryhackme.com/room/sqlmap)
4049
* _RTFM: SQLMap - pg. 71_
4150
* _Operator Handbook: SQLMap - pg. 284_
51+
{% endtab %}
4252

43-
### **Config and help commands**
44-
53+
{% tab title="Config/help cmds" %}
4554
Specify the database type if not SQL
4655

4756
```
@@ -60,6 +69,10 @@ Help
6069
# sqlmap --wizard
6170
```
6271

72+
73+
{% endtab %}
74+
75+
{% tab title="Cmds - GET" %}
6376
### Commands GET parameter - injection passed in the URL itself
6477

6578
Test if sql inject is valid (will return banner on success)
@@ -97,27 +110,39 @@ WAF bypass and shell setup
97110
```
98111
# sqlmap -u http://10.11.0.22/debug.php?id=1 -p "id" --dbms=mysql --os-shell
99112
```
113+
{% endtab %}
100114

115+
{% tab title="Cmds - POST" %}
101116
### Commands POST parameter - injection passed in the data section
102117

103118
Test if sql inject is valid (will return banner on success)
104119

105120
```
106121
# sqlmap -u “http://domain.com” --data="user=test&pass=test" -b
107122
```
123+
{% endtab %}
124+
{% endtabs %}
125+
126+
<details>
108127

109-
### SQLmap with Burp
128+
<summary>SQLmap with Burp</summary>
110129

111130
* Start SQLmap API on your kali box while Burp Proxy Pro can be runnign anywhere
112131
* When Burp finds an SQL injection, it will connect to SQLmap's running API to automaticallu attack the vulnerable parameters.
113132
* Start SQLmap API
114133
* \# cd /opt/sqlmap
115134
* \# python sqlmapapi.py -s \[ip] -p \[port]
116135

136+
</details>
137+
117138
{% embed url="https://youtu.be/2YD4vygeghM" %}
118139

119140
## Other Tools
120141

142+
<details>
143+
144+
<summary>Other Tools</summary>
145+
121146
* [PowerUpSQL](https://github.com/NetSPI/PowerUpSQL) - A PowerShell Toolkit for Attacking SQL Server
122147
* [https://github.com/NetSPI/PowerUpSQL/wiki](https://github.com/NetSPI/PowerUpSQL/wiki)
123148
* [https://github.com/NetSPI/PowerUpSQL/wiki/PowerUpSQL-Cheat-Sheet](https://github.com/NetSPI/PowerUpSQL/wiki/PowerUpSQL-Cheat-Sheet)
@@ -139,15 +164,19 @@ Test if sql inject is valid (will return banner on success)
139164
* [https://github.com/youngyangyang04/NoSQLAttack](https://github.com/youngyangyang04/NoSQLAttack) - **A SQLi vulnerability scanner for mongoDB**
140165
* [https://github.com/WhitewidowScanner/whitewidow](https://github.com/WhitewidowScanner/whitewidow) - **Another SQL vulnerability scanner**
141166

167+
</details>
168+
142169
## **SQL Basics**
143170

144171
{% content-ref url="sql-methodology.md" %}
145172
[sql-methodology.md](sql-methodology.md)
146173
{% endcontent-ref %}
147174

148-
## Techniques
175+
## Attack Techniques
176+
177+
<details>
149178

150-
### Filter evasion
179+
<summary>Filter evasion</summary>
151180

152181
* Many applications use web application firewalls (WAF) to help protect against any kind of SQL injection vulnerability. The only problem is that WAFs only look for certain words, characters, or patterns, meaning certain special characters used in combination can be used to evade WAF filter protection.
153182
* For example, a very basic WAF may filter out specific SQL keywords such as `OR`, `SELECT`, `UNION` or `WHERE` to prevent them from being used in SQL injection attacks.
@@ -166,9 +195,13 @@ Test if sql inject is valid (will return banner on success)
166195
* **String Splitting** - You can split strings within the query to bypass various filters. MySQL will still execute them as keywords.
167196
* `un?+un/**/ion+se/**/lect+`
168197

169-
### String Concatenation
170198

171199

200+
</details>
201+
202+
<details>
203+
204+
<summary>String Concatenation</summary>
172205

173206
An input field may restrict the usage of certain datatypes and/or words/punctuation. This can make the exploitation of SQL injection vulnerabilities a little bit more difficult. However, two functions can be used in conjunction to bypass filters such as these:`CHAR()` and `CONCAT()`.
174207

@@ -186,7 +219,11 @@ An input field may restrict the usage of certain datatypes and/or words/punctuat
186219
Strings can be encoded into their Hex values either by passing a hex value or using the `HEX()` function.
187220
* For example, the string 'password' can be passed to an SQL statement like this: `SELECT 0x70617373776f726`
188221

189-
### **Retrieve Hidden Data**
222+
</details>
223+
224+
<details>
225+
226+
<summary>Retrieve Hidden Data</summary>
190227

191228
* When retrieving items from a database via an SQL query, some results may be filtered with a restriction clause at the end of the of the query&#x20;
192229
* In a vulnerable parameter, we can insert ‘--’ which is the SQL code for a comment. This will “comment out” the rest of the query, there for removing any restrictions placed on it.
@@ -200,7 +237,11 @@ An input field may restrict the usage of certain datatypes and/or words/punctuat
200237
* &#x20;Resulted query: `SELECT * FROM products WHERE category = 'Gifts' OR 1=1--' AND released = 1`
201238
*  [https://portswigger.net/web-security/sql-injection/lab-retrieve-hidden-data](https://portswigger.net/web-security/sql-injection/lab-retrieve-hidden-data)
202239

203-
### **Subvert App Logic/Login Bypass**
240+
</details>
241+
242+
<details>
243+
244+
<summary>Subvert App Logic/Login Bypass</summary>
204245

205246
* When an application checks login credentials, it submits in a query, usually with the fields of a username and password. If the query returns with the user details, the login is successful.
206247
* One way of bypassing the login requirement of the password, is to comment out the part of the query, after the username
@@ -213,6 +254,8 @@ An input field may restrict the usage of certain datatypes and/or words/punctuat
213254
* [http://www.securityidiots.com/Web-Pentest/SQL-Injection/bypass-login-using-sql-injection.html](http://www.securityidiots.com/Web-Pentest/SQL-Injection/bypass-login-using-sql-injection.html)
214255
* [https://portswigger.net/web-security/sql-injection/lab-login-bypass](https://portswigger.net/web-security/sql-injection/lab-login-bypass)
215256

257+
</details>
258+
216259
## **Manual Injection Methodology**
217260

218261
{% content-ref url="manual-injection-methodology.md" %}

0 commit comments

Comments
 (0)