-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from austimkelly/develop
Develop
- Loading branch information
Showing
9 changed files
with
262 additions
and
0 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,82 @@ | ||
# For most projects, this workflow file will not need changing; you simply need | ||
# to commit it to your repository. | ||
# | ||
# You may wish to alter this file to override the set of languages analyzed, | ||
# or to provide custom queries or build logic. | ||
# | ||
# ******** NOTE ******** | ||
# We have attempted to detect the languages in your repository. Please check | ||
# the `language` matrix defined below to confirm you have the correct set of | ||
# supported CodeQL languages. | ||
# | ||
name: "CodeQL" | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
# The branches below must be a subset of the branches above | ||
branches: [ "main", "develop" ] | ||
schedule: | ||
- cron: '38 4 * * 3' | ||
|
||
jobs: | ||
analyze: | ||
name: Analyze | ||
# Runner size impacts CodeQL analysis time. To learn more, please see: | ||
# - https://gh.io/recommended-hardware-resources-for-running-codeql | ||
# - https://gh.io/supported-runners-and-hardware-resources | ||
# - https://gh.io/using-larger-runners | ||
# Consider using larger runners for possible analysis time improvements. | ||
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }} | ||
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} | ||
permissions: | ||
actions: read | ||
contents: read | ||
security-events: write | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
language: [ ] | ||
# CodeQL supports [ 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift' ] | ||
# Use only 'java-kotlin' to analyze code written in Java, Kotlin or both | ||
# Use only 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both | ||
# Learn more about CodeQL language support at https://aka.ms/codeql-docs/language-support | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
# Initializes the CodeQL tools for scanning. | ||
- name: Initialize CodeQL | ||
uses: github/codeql-action/init@v2 | ||
with: | ||
languages: ${{ matrix.language }} | ||
# If you wish to specify custom queries, you can do so here or in a config file. | ||
# By default, queries listed here will override any specified in a config file. | ||
# Prefix the list here with "+" to use these queries and those in the config file. | ||
|
||
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs | ||
# queries: security-extended,security-and-quality | ||
|
||
|
||
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift). | ||
# If this step fails, then you should remove it and run the build manually (see below) | ||
- name: Autobuild | ||
uses: github/codeql-action/autobuild@v2 | ||
|
||
# ℹ️ Command-line programs to run using the OS shell. | ||
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun | ||
|
||
# If the Autobuild fails above, remove it and uncomment the following three lines. | ||
# modify them (or add more) to build your code if your project, please refer to the EXAMPLE below for guidance. | ||
|
||
# - run: | | ||
# echo "Run, Build Application using script" | ||
# ./location_of_script_within_repo/buildscript.sh | ||
|
||
- name: Perform CodeQL Analysis | ||
uses: github/codeql-action/analyze@v2 | ||
with: | ||
category: "/language:${{matrix.language}}" |
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,3 +1,6 @@ | ||
._ | ||
.DS_Store | ||
|
||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
|
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,42 @@ | ||
from flask import Flask, render_template, jsonify, request | ||
|
||
app = Flask(__name__) | ||
|
||
# Dummy data representing a list of users | ||
users = [ | ||
{"id": 1, "name": "Alice"}, | ||
{"id": 2, "name": "Bob"}, | ||
{"id": 3, "name": "Charlie"} | ||
] | ||
|
||
# Route to get user details by ID | ||
@app.route('/api/users/<int:user_id>', methods=['GET']) | ||
def get_user(user_id): | ||
user = next((u for u in users if u["id"] == user_id), None) | ||
|
||
if user: | ||
return jsonify(user) | ||
else: | ||
return jsonify({"error": "User not found"}), 404 | ||
|
||
# Route to update user details by ID (Vulnerable to IDOR) | ||
@app.route('/api/users/<int:user_id>', methods=['PUT']) | ||
def update_user(user_id): | ||
data = request.get_json() | ||
|
||
# In a real application, proper authentication and authorization checks should be performed here | ||
|
||
user = next((u for u in users if u["id"] == user_id), None) | ||
if user: | ||
user["name"] = data.get("name", user["name"]) | ||
return jsonify({"message": "User updated successfully"}) | ||
else: | ||
return jsonify({"error": "User not found"}), 404 | ||
|
||
# Route for the root URL ("/") to render the HTML page | ||
@app.route('/') | ||
def index(): | ||
return render_template('index.html') | ||
|
||
if __name__ == '__main__': | ||
app.run(debug=True) |
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,30 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>REST API Example</title> | ||
</head> | ||
<body> | ||
<h1>REST API Example</h1> | ||
<p>This is a simple example of a REST API with a potential Insecure Direct Object Reference (IDOR) vulnerability.</p> | ||
|
||
<h2>Instructions</h2> | ||
<p>Interact with the API by making GET and PUT requests using a tool like <code>curl</code>:</p> | ||
|
||
<h3>GET User Details</h3> | ||
<p>Retrieve user details by making a GET request:</p> | ||
<pre> | ||
curl http://127.0.0.1:5000/api/users/1 | ||
</pre> | ||
|
||
<h3>UPDATE User Details (Vulnerable to IDOR)</h3> | ||
<p>Update user details by making a PUT request. Modify the user ID in the URL to demonstrate the IDOR vulnerability:</p> | ||
<pre> | ||
curl -X PUT -H "Content-Type: application/json" -d '{"name": "NewName"}' http://127.0.0.1:5000/api/users/2 | ||
</pre> | ||
|
||
<p><strong>Note:</strong> This example is for educational purposes only. In a real-world scenario, proper authentication and authorization checks should be implemented to prevent security vulnerabilities.</p> | ||
</body> | ||
</html> |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import sqlite3 | ||
|
||
def create_and_populate_database(): | ||
# Connect to the database (this will create it if it doesn't exist) | ||
connection = sqlite3.connect("example.db") | ||
cursor = connection.cursor() | ||
|
||
# Create a users table if it doesn't exist | ||
cursor.execute("CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY, username TEXT)") | ||
|
||
# Insert some dummy data | ||
dummy_data = [("JohnDoe",), ("AliceSmith",), ("BobJohnson",)] | ||
cursor.executemany("INSERT INTO users (username) VALUES (?)", dummy_data) | ||
|
||
# Commit changes and close the connection | ||
connection.commit() | ||
connection.close() | ||
|
||
def vulnerable_query(username): | ||
# Vulnerable code with improperly escaped user input | ||
query = "SELECT * FROM users WHERE username = '" + username + "'" | ||
|
||
# Connecting to the database | ||
connection = sqlite3.connect("example.db") | ||
cursor = connection.cursor() | ||
|
||
# Executing the vulnerable query | ||
cursor.execute(query) | ||
|
||
# Fetching the results | ||
results = cursor.fetchall() | ||
|
||
# Closing the database connection | ||
connection.close() | ||
|
||
return results | ||
|
||
# Create and populate the database | ||
create_and_populate_database() | ||
|
||
# Test the vulnerable query | ||
user_input = input("Enter username: ") # Enter: ' OR '1'='1' -- | ||
result = vulnerable_query(user_input) | ||
|
||
# Display the results | ||
print(result) |
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,40 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>XSS Demo</title> | ||
</head> | ||
<body> | ||
<h1>XSS Demo</h1> | ||
<p>This is a vulnerable page that allows XSS.</p> | ||
|
||
|
||
<!-- Visual demonstration of XSS prevention --> | ||
<div style="border: 2px solid #000; padding: 10px; margin-top: 20px;"> | ||
<h3>Visual Demonstration of XSS Prevention</h3> | ||
<p> | ||
Original Vulnerable Input: | ||
<span style="color: red;">{{ user_input }}</span> | ||
</p> | ||
<p> | ||
Properly Sanitized Input: | ||
<span style="color: green;">{{ user_input|safe|replace('\n', '<br>') }}</span> | ||
</p> | ||
</div> | ||
|
||
<!-- Instructions for the user --> | ||
<p> | ||
<strong>Example:</strong> Enter <code>Hello World! <script>alert('Cross-Side Scripting!');</script></code> into the text box | ||
to show an XSS vulnerability as well as a sanitized input. | ||
</p> | ||
|
||
<!-- Form for user input --> | ||
<form method="post" action="/"> | ||
<label for="user_input">Enter Your Input:</label> | ||
<input type="text" name="user_input" id="user_input" required> | ||
<button type="submit">Submit</button> | ||
</form> | ||
</body> | ||
</html> |
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,19 @@ | ||
from flask import Flask, render_template, request | ||
import html # Import the html module for escaping | ||
|
||
app = Flask(__name__) | ||
|
||
@app.route('/', methods=['GET', 'POST']) | ||
def index(): | ||
user_input = '' | ||
if request.method == 'POST': | ||
# Retrieve user input from the form | ||
user_input = request.form.get('user_input', '') | ||
|
||
# Display user input directly without proper sanitization (for demonstration purposes) | ||
return render_template('index.html', user_input=user_input, display_script=True) | ||
|
||
return render_template('index.html', user_input=user_input, display_script=False) | ||
|
||
if __name__ == '__main__': | ||
app.run(debug=True, port=5001) |