-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add code injection via template (#961)
- Loading branch information
Showing
8 changed files
with
221 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,11 +59,39 @@ Here are the exploitable vulnerable packages: | |
|
||
* Open Redirect | ||
* NoSQL Injection | ||
* Code Injection | ||
* Command execution | ||
* Cross-site Scripting (XSS) | ||
* Security misconfiguration exposes server information | ||
* Insecure protocol (HTTP) communication | ||
|
||
#### Code injection | ||
|
||
The page at `/account_details` is rendered as an Handlebars view. | ||
|
||
The same view is used for both the GET request which shows the account details, as well as the form itself for a POST request which updates the account details. A so-called Server-side Rendering. | ||
|
||
The form is completely functional. The way it works is, it receives the profile information from the `req.body` and passes it, as-is to the template. This however means, that the attacker is able to control a variable that flows directly from the request into the view template library. | ||
|
||
You'd think that what's the worst that can happen because we use a validation to confirm the expected input, however the validation doesn't take into account a new field that can be added to the object, such as `layout`, which when passed to a template language, could lead to Local File Inclusion (Path Traversal) vulnerabilities. Here is a proof-of-concept showing it: | ||
|
||
```sh | ||
curl -X 'POST' -H 'Content-Type: application/json' --data-binary $'{"layout": "./../package.json"}' 'http://localhost:3001/account_details' | ||
``` | ||
|
||
Actually, there's even another vulnerability in this code. | ||
The `validator` library that we use has several known regular expression denial of service vulnerabilities. One of them, is associated with the email regex, which if validated with the `{allow_display_name: true}` option then we can trigger a denial of service for this route: | ||
|
||
```sh | ||
curl -X 'POST' -H 'Content-Type: application/json' --data-binary "{\"email\": \"`seq -s "" -f "<" 100000`\"}" 'http://localhost:3001/account_details' | ||
``` | ||
|
||
The `validator.rtrim()` sanitizer is also vulnerable, and we can use this to create a similar denial of service attack: | ||
|
||
```sh | ||
curl -X 'POST' -H 'Content-Type: application/json' --data-binary "{\"email\": \"[email protected]\", \"country\": \"nop\", \"phone\": \"0501234123\", \"lastname\": \"nop\", \"firstname\": \"`node -e 'console.log(" ".repeat(100000) + "!")'`\"}" 'http://localhost:3001/account_details' | ||
``` | ||
|
||
#### Open redirect | ||
|
||
The `/admin` view introduces a `redirectPage` query path, as follows in the admin view: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
|
||
<style> | ||
strong {font-weight: bold} | ||
</style> | ||
{{#if firstname}} | ||
<h1 id="page-title">Account details for: {{firstname}}</h1> | ||
<center> | ||
<h3 style="color: green">details saved</h2> | ||
</center> | ||
{{else}} | ||
<h1 id="page-title" style="color: red">Account details missing</h1> | ||
{{/if}} | ||
|
||
<div id="list"> | ||
<form action="/account_details" method="POST" accept-charset="utf-8"> | ||
<div class="item-new"> | ||
<center>First name</center> | ||
<input class="input" type="text" name="firstname" value="{{firstname}}" /> | ||
<br/> | ||
|
||
<center>Last name</center> | ||
<input class="input" type="text" name="lastname" value="{{lastname}}" /> | ||
<br/> | ||
|
||
<center>Country</center> | ||
<input class="input" type="text" name="country" value="{{country}}" /> | ||
<br/> | ||
|
||
<center>Phone number</center> | ||
<input class="input" type="text" name="phone" value="{{phone}}" /> | ||
<br/> | ||
|
||
<center>Email</center> | ||
<input class="input" type="text" name="email" value="{{email}}" /> | ||
<br/> | ||
|
||
</div> | ||
|
||
<br/> | ||
<br/> | ||
<button type="submit">Save account details</button> | ||
|
||
</form> | ||
</div> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title><%= title %></title> | ||
<link rel='stylesheet' href='/public/css/screen.css' /> | ||
<!--[if lt IE 9]> | ||
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> | ||
<![endif]--> | ||
</head> | ||
<body> | ||
<div id="layout"> | ||
{{{body}}} | ||
<div id="layout-footer"></div> | ||
</div> | ||
<div id="footer-wrap"> | ||
|
||
<div id="footer"> | ||
<center> | ||
<a href="/public/about.html">about</a> | ||
</center> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |