Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update A1 - Copy-n-Paste README #165

Merged
merged 69 commits into from
May 21, 2019
Merged
Changes from 1 commit
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
24b6dc0
[DOCS] Add attack into README
rafaveira3 Feb 10, 2019
86b6a54
[DOCS] Add index
vitoriario Feb 11, 2019
115681b
[FIX] Fix objectives link
vitoriario Feb 11, 2019
11144e2
[DOCS] Move attack pictures to images folder
vitoriario Feb 11, 2019
437d813
[DOCS] correct misspelling
vitoriario Feb 11, 2019
bc594a4
[FEAT] Redirect / to /login
vitoriario Feb 26, 2019
99789e0
Merge pull request #202 from vitoriario/redirect_login
rafaveira3 Feb 26, 2019
1d4046a
[FEAT] WIP: Add new A9 app Stegonography
Krlier Mar 17, 2019
f5712cf
Fix typo in README.md
Krlier Apr 1, 2019
b47041a
Merge branch 'master' of github.com:globocom/secDevLabs into Stegonog…
Krlier Apr 14, 2019
3cc941d
[FEAT] Stegonography first commit 🚀
Krlier Apr 14, 2019
076531c
[FEAT] Add README file
Krlier Apr 19, 2019
50f8045
[FEAT] Add attack narrative images
Krlier Apr 19, 2019
1bbbf50
[FEAT] Add admin's page
Krlier Apr 19, 2019
ff7d5dc
[FEAT] Change session token name
Krlier Apr 19, 2019
d48adbc
[REFACT] Change Stegonography from A9 to A6
Krlier Apr 19, 2019
5981d08
[FEAT] Update README.md
Krlier Apr 19, 2019
9db240c
[REFACT] Update README.md
Krlier Apr 23, 2019
ea40d63
Merge branch 'Stegonography' of github.com:globocom/secDevLabs into S…
Krlier Apr 23, 2019
8337eec
[REFACT] Move node_modules to app folder
Krlier May 2, 2019
1e51f73
[FEAT] Add dependencies to node_modules
Krlier May 2, 2019
bb5b6f5
[REFACT] Add mongodb to hold credentials
Krlier May 2, 2019
975786d
[DOCS] Update README file
Krlier May 2, 2019
93379f9
[FEAT] Add new routes
Krlier May 2, 2019
141f945
[FEAT] Update dependencies
Krlier May 2, 2019
a2ff06f
[DOCS] Update README
Krlier May 2, 2019
fb34c8a
[FIX] Logout route now clears cookie correctly
Krlier May 2, 2019
0d6e56b
Merge pull request #226 from globocom/Stegonography
spimpaov May 2, 2019
99757b4
[DOCS] Update README with new A6 app
Krlier May 2, 2019
46fee5d
Merge pull request #227 from globocom/Update-Readme
spimpaov May 2, 2019
00d71b5
[DOCS] Update README to have the Attack Narrative
Krlier May 9, 2019
be533c1
[DOCS] Remove ATTACK.md and move it's images
Krlier May 9, 2019
f4da66a
[DOCS] Update README to contemplate the Attack Narrative
Krlier May 9, 2019
c6b51af
[DOCS] Remove docs folder and move itsimages
Krlier May 9, 2019
7fd573e
[DOCS] Update README file to contemplate the Attack Narrative
Krlier May 9, 2019
ee0284d
[DOCS] Remove docs folder and move it's images
Krlier May 9, 2019
5f55be7
[DOCS] Update README to contemplate the Attack Narrative
Krlier May 9, 2019
43c4397
[DOCS] Remove docs folder and move it's images
Krlier May 9, 2019
0ca0519
[DOCS] Remove docs folder
Krlier May 9, 2019
0570df9
[FEAT] Add verbose response to successful login route
May 9, 2019
07de238
Merge pull request #233 from Takehime/a2-feat
Krlier May 9, 2019
0547d70
[DOCS] Update README file to contemplate the Attack Narrative
Krlier May 9, 2019
4916bc5
[DOCS] Remove the docs folder and move it's images
Krlier May 9, 2019
9cd95d1
Merge pull request #232 from globocom/A4-VinijrBlog-Update-Readme
spimpaov May 9, 2019
1e59c29
Merge pull request #229 from globocom/A2-Saidajaula-Update-README
spimpaov May 9, 2019
a0698da
Merge pull request #230 from globocom/A2-InsecureGoProject-Update-Readme
spimpaov May 9, 2019
65d630c
Merge pull request #231 from globocom/A3-SnakePro-Update-Readme
spimpaov May 9, 2019
aab1552
Merge pull request #234 from globocom/A5-EcommerceAPI-Update-Readme
spimpaov May 9, 2019
d2a22ac
[DOCS] Fix Objectives link
spimpaov May 13, 2019
f3f48d3
[DOCS] Fix Objectives link
spimpaov May 13, 2019
7e657d1
[DOCS] Fix Objectives link
spimpaov May 13, 2019
36d689d
[DOCS] Fix Objectives link
spimpaov May 13, 2019
0932cec
[DOCS] Fix Objectives link
spimpaov May 13, 2019
50415ab
[DOCS] Update A3 README
spimpaov May 13, 2019
457b093
[DOCS] Fix broken ink in A4 README
spimpaov May 13, 2019
39e9f65
Merge pull request #241 from globocom/fix-objectives
Krlier May 14, 2019
174c79d
[DOCS] Update README.md "objectives" link
Krlier May 14, 2019
c07b46f
Merge pull request #242 from globocom/fix-obj-a3
Krlier May 14, 2019
09f710c
Merge pull request #243 from globocom/fix-obj-a2
Krlier May 14, 2019
31ed41b
Merge pull request #244 from globocom/fix-obj-a4
Krlier May 14, 2019
1d77fee
Merge pull request #245 from globocom/fix-obj-a5
Krlier May 14, 2019
6ed317b
Merge pull request #246 from globocom/readme-a3
Krlier May 14, 2019
67a2030
Merge pull request #247 from globocom/readme-a4
Krlier May 14, 2019
b59689f
[DOCS] Remove docs folder
Krlier May 14, 2019
011c117
Merge branch 'change-a1-docs' of github.com:globocom/secDevLabs into …
Krlier May 14, 2019
c387924
[DOCS] Update README with A1 final version
Krlier May 14, 2019
43ce9ce
[DOCS] Fix typo in Readme
spimpaov May 20, 2019
31b0bed
[DOCS] Add payload in A1 Readme
spimpaov May 20, 2019
0ca3fdf
[DOCS] Fix typo
Krlier May 21, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[FEAT] Add README file
  • Loading branch information
Krlier committed Apr 19, 2019
commit 076531cdc0a9ff03c6b82845412be085dc493815
131 changes: 40 additions & 91 deletions owasp-top10-2017-apps/a6/stegonography/README.md
Original file line number Diff line number Diff line change
@@ -11,15 +11,15 @@ Stegonography is a Node.js web application that uses an API and a simple front e
- [Definition](#what-is-security-misconfiguration)
- [Setup](#setup)
- [Attack narrative](#attack-narrative)
- [Objectives](#secure-this-app)
- [Objectives](#secure-this-app-🔧)
- [Solutions](#pr-solutions)
- [Contributing](#contributing)

## What is Security Misconfiguration?

Security misconfiguration can happen at any level of an application stack, including the network services, platform, web server, application server, database, frameworks, custom code, and pre-installed virtual machines, containers, or storage. Automated scanners are useful for detecting misconfigurations, use of default accounts or configurations, unnecessary services, legacy options, etc.

The main goal of this project is to discuss how **Security Misconfiguration** vulnerabilities can be exploited and to encourage developers send Pull Requests to secDevLabs on how they would mitigate these flaws.
The main goal of this project is to discuss how **Security Misconfiguration** vulnerabilities can be exploited and to encourage developers to send secDevLabs Pull Requests on how they would mitigate these flaws.

## Setup

@@ -35,130 +35,79 @@ make install

Then simply visit [localhost:10006][App] ! 😆

## Get to know steps
## Get to know the app 🦕

To properly understand how this application works, you can follow these simple steps:

- Register a new user via front-end.
- Login as this user via front-end.
* Register another user now using command line:
```sh
curl -s -H "Content-Type: application/json" -d '{"user":"bob", "pass":"password", "passcheck":"password"}' http://localhost:3000/register
```
* Login as this second user now using command line:
```sh
curl -s -H "Content-Type: application/json" -d '{"user":"bob", "pass":"password"}' http://localhost:3000/login

```
- Try adding an hidden message to an image.
- Try hiding a message with a password!
- Decrypt a friends message!

## Attack narrative

Now that you know the purpose of this app, what could go wrong? The following section descrides how an attacker could identify and exploit an SQL Injection in CopyNPaste app. We encourage you follow these steps and try to reproduce the attack itself before reading any code.

#### Vulnerability identification 👀

After reviewing `NewUser()` , `CheckIfUserExists()` and `AuthenticateUser()` from [`db.go`]((https://github.com/globocom/secDevLabs/blob/master/owasp-top10-2017-apps/a1/copy-n-paste/app/util/db.go#)) file, it was possibile to see that some input from users are concatenated with SQL queries, as shown in the following codes:

```go
query := fmt.Sprint("select * from Users where username = '" + user + "'")

```

```go
query := fmt.Sprint("insert into Users (username, password) values ('" + user + "', '" + passHash + "')")
```

```go
query := fmt.Sprint("select username from Users where username = '" + username + "'")
```

As no validation is present to these variables, SQL injections may be successfuly executed in the database. Using web interface, we send some information using form for inspect how web interface comunicates with API.

<img src="images/attack-0.png" align="center"/>

To confirm this, the following payload could be used that, if the application is indeed vulnerable, a 5 seconds delay will be noted after sending it:

<img src="images/attack-1.png" align="center"/>

Using `curl` on CLI interface, we can test again (with a 30 seconds delay):

```sh
curl -s -H "Content-Type: application/json" -d '{"user":"-1'\'' union select 1,2,sleep(30) -- ", "pass":"password"}' http://127.0.0.1:3000/login
```

Request:
Now that you know the purpose of this app, what could possibly go wrong? The following section describes how an attacker could identify and eventually find sensitive information about the app or it's users. We encourage you to follow these steps and try to reproduce them on your own to better understand the attack vector! 😜

<img src="images/attack-2.png" align="center"/>
### Vulnerability identification 👀

30 seconds later:
#### Error stack traces are output to end users

<img src="images/attack-3.png" align="center"/>
An attacker, when trying to enumerate available pages on the application, could come across a verbose error stack trace with potentially sensitive information that could compromise the app. An example of a verbose error stack trace is as shown by the image below:

#### Vulnerability exploitation 🔥

An attacker could now create any malicious SQL queries and send to the API that, in theory, will be executed. For this attack narrative, [sqlmap](https://github.com/sqlmapproject/sqlmap) will be used to exemplify how an automated SQL Injection attack may be performed.

To install sqlmap on Mac you can simply type:
<p align="center">
<img src="images/stack_trace.png"/>
</p>

```sh
brew install sqlmap
```
#### Default username and passwords are being used in a production environment

First possible step is to create a `postRequest.txt` containing the HTTP POST itself, as shown in the following code:
Using [Dirb] to enumerate existing pages on the application and hide the "Not Found" with the `-N 401` flag, it's possible to find what seems to be a login page, as pointed in the image below:

```sh
POST /login HTTP/1.1
Host: 127.0.0.1:3000
User-Agent: curl/7.54.0
Accept: */*
Content-Type: application/json
Content-Length: 31

{"user":"user", "pass":"password"}
dirb http://localhost:10006 -N 401
```

Before executing the attack, you can open a new tab in your terminal and type the following command to observe how the malicious requests will come to the app:

```sh
docker logs a1_api -f
```
<p align="center">
<img src="images/dirb_result.png"/>
</p>

After that, we could now use `-r` option and wait sqlmap perform multiples malicious requests until it finds the vulnerable parameter:
By visiting `http://localhost:10006/login` we get to the following screen:

```sh
sqlmap -r postRequest.txt
```
<p align="center">
<img src="images/login_page.png"/>
</p>

<img src="images/attack-4.png" align="center"/>
A quick guess with the credentials `admin:admin` and we can successfully log-in to the application and get to the admin's control-panel, as shown by the image below:

After understanding how this database is structured, an attacker could use the following command to retrieve database details:
<p align="center">
<img src="images/admin_page.png"/>
</p>

```sh
sqlmap -r postRequest.txt --tables
```
#### Verbose session token gives away unnecessary information

And then retrieve sensitive information from it:
After logging in to the application, it's possible to see it sets a session token: `jwtSessionToken`. As shown by the following image:

```sh
sqlmap -r postRequest.txt -D a1db -T Users --dump
```
<p align="center">
<img src="images/jwt_token.png"/>
</p>

<img src="images/attack-5.png" align="center"/>
Even though using verbose tokens might not pose a straight forward security vulnerability, on certain apps it might give away the hint an attacker needs tocompromise it's security. 🕵️‍

## Secure this app 🔧

How could you now migitate this vulnerability? After your code modification, an attacker should not be able to:
How would you migitate this vulnerability? After your changes, an attacker should not be able to:

* Execute SQL queries into database.
* See error stack traces
* Log-in with default credentials
* See verbose token names

## PR solutions

[Spoiler alert] To understand how this vulnerability can be mitigated, check [these pull requests](https://github.com/globocom/secDevLabs/pulls?q=is%3Apr+label%3A%22mitigation+solution+%F0%9F%94%92%22+label%3A%22CopyNPaste+API%22)!
[Spoiler alert 🚨] To understand how this vulnerability can be mitigated, check out [these pull requests](https://github.com/globocom/secDevLabs/pulls?utf8=%E2%9C%93&q=is%3Aclosed+is%3Apr+label%3AA6-OWASP-2017+label%3AStegonography)!

## Contributing

We encourage you to contribute to SecDevLabs! Please check out the [Contributing to SecDevLabs](../../../docs/CONTRIBUTING.md) section for guidelines on how to proceed! 🎉

[Docker Install]: https://docs.docker.com/install/
[Docker Compose Install]: https://docs.docker.com/compose/install/
[App]: http://localhost:10006
[App]: http://localhost:10006
[Dirb]: https://tools.kali.org/web-applications/dirb