Skip to content

Commit b501065

Browse files
committed
refactor: update "A8:2019 - Injection" section
1 parent 17ecba9 commit b501065

File tree

1 file changed

+74
-13
lines changed

1 file changed

+74
-13
lines changed

2019/en/0xa8-injection.md

Lines changed: 74 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,97 @@ A8:2019 Injection
22
=================
33

44
| Threat agents/Attack vectors | Security Weakness | Impacts |
5-
| -- | -- | -- |
6-
| Access Lvl : Exploitability ? | Prevalence ? : Detectability ? | Technical ? : Business |
7-
| | | |
5+
| - | - | - |
6+
| API Specific : Exploitability **3** | Prevalence **2** : Detectability **3** | Technical **3** : Business Specific |
7+
| Attackers will feed the API with hostile data through whatever injection vectors are available (e.g. direct input, parameters, integrated services, etc.) expecting it to e sent to an interpreter. | Injection flaws are very common and often found in SQL, LDAP or NoSQL queries, OS commands, XML parsers and ORM. These flaws are easy to discover when reviewing the source code. Attackers can use scanners and fuzzers. | Injection can lead to information disclosure and data loss. It may also lead to DoS or complete host takeover. |
88

99
## Is the API Vulnerable?
1010

11+
The API is vulnerable to injection flaws if:
12+
13+
* Client-supplied data is not validated, filtered or sanitized by the API.
14+
* Client-supplied data is directly used or concatenated to SQL/NoSQL/LDAP
15+
queries, OS commands, XML parsers. and Object Relational Mapping (ORM)/Object
16+
Document Mapper (ODM).
17+
* Data coming from external systems (e.g. integrated systems) is not validated,
18+
filtered or sanitized by the API.
19+
1120
## Example Attack Scenarios
1221

1322
### Scenario #1
1423

24+
Inspecting the web browser network traffic an attacker identifies the following
25+
API request responsible to start the recovery password workflow:
26+
27+
```
28+
POST /api/accounts/recovery
29+
{"username": "[email protected]"}
30+
```
31+
32+
The attacker replays the request with a different payload
33+
34+
```
35+
POST /api/account/recovery
36+
{"email": "[email protected]';WAITFOR DELAY '0:0:5'--"}
37+
```
38+
39+
This time the response took ~5 seconds confirming the API is vulnerable to SQL
40+
injection. Exploiting this vulnerability the attacker was able to gain
41+
unauthorized access to the system.
42+
1543
### Scenario #2
1644

17-
A parental control device firmware provides the endpoint `/api/CONFIG/restore`
18-
which expects an `appId` to be sent as a multipart parameter. Using a decompiler
19-
an attacker finds out that the `appId` is passed directly into a system call
20-
without any sanitization. The following command allows the attacker to shutdown
21-
any device with the same vulnerable firmware
22-
`curl -k "https://${deviceIP}:4567/api/CONFIG/restore" -F ‘appid=$(/etc/pod/power_down.sh)’`.
45+
Firmware of a parental control device provides the endpoint
46+
`/api/CONFIG/restore` which expects an appId to be sent as a multipart
47+
parameter. Using a decompiler an attacker finds out that the appId is passed
48+
directly into a system call without any sanitization:
49+
50+
```c
51+
snprintf(cmd, 128, "%srestore_backup.sh /tmp/postfile.bin %s %d",
52+
"/mnt/shares/usr/bin/scripts/", appid, 66);
53+
system(cmd);
54+
```
55+
56+
The following command allows the attacker to shutdown any device with the same
57+
vulnerable firmware:
58+
59+
```
60+
$ curl -k "https://${deviceIP}:4567/api/CONFIG/restore" -F 'appid=$(/etc/pod/power_down.sh)'
61+
```
2362
2463
## How To Prevent
2564
65+
Preventing injection requires keeping data separate from commands and queries.
66+
67+
* Perform data validation using a single, trustworthy, actively maintained
68+
library.
69+
* Validate, filter and sanitize all client-provided data or other data coming
70+
from integrated systems.
71+
* Special characters should be escaped using the specific syntax for the target
72+
interpreter.
73+
* Prefer a safe API which provides a parameterized interface.
74+
* Always limit the number of returned records to prevent mass disclosure in case
75+
of injection.
76+
2677
## References
2778
2879
### OWASP
2980
30-
* [Command Injection][1]
81+
* [OWASP Injection Flaws][1]
82+
* [SQL Injection][2]
83+
* [NoSQL Injection Fun with Objects and Arrays][3]
84+
* [Command Injection][4]
3185
3286
### External
3387
34-
* [HOW TO: Command Injection, HackerOne][2]
88+
* [CWE-77: Command Injection][5]
89+
* [CWE-89: SQL Injection][6]
90+
* [HOW TO: Command Injection, HackerOne][7]
3591
36-
[1]: https://www.owasp.org/index.php/Command_Injection
37-
[2]: https://www.hackerone.com/blog/how-to-command-injections
92+
[1]: https://www.owasp.org/index.php/Injection_Flaws
93+
[2]: https://www.owasp.org/index.php/SQL_Injection
94+
[3]: https://www.owasp.org/images/e/ed/GOD16-NOSQL.pdf
95+
[4]: https://www.owasp.org/index.php/Command_Injection
96+
[5]: https://cwe.mitre.org/data/definitions/77.html
97+
[6]: https://cwe.mitre.org/data/definitions/89.html
98+
[7]: https://www.hackerone.com/blog/how-to-command-injections

0 commit comments

Comments
 (0)