-
Notifications
You must be signed in to change notification settings - Fork 1
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 #110 from AikidoSec/bugfix-psycopg2-with-django
psycopg2 : Only wrap psycopg2._ext.cursor class
- Loading branch information
Showing
25 changed files
with
466 additions
and
135 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
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,6 @@ | ||
SECRET_KEY="test_key" | ||
|
||
# Aikido keys | ||
AIKIDO_DEBUG=true | ||
AIKIDO_TOKEN="AIK_secret_token" | ||
AIKIDO_BLOCKING=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,23 @@ | ||
# Use an official Python runtime as a parent image | ||
FROM python:3 | ||
|
||
#Copy code base | ||
COPY ./ /tmp | ||
|
||
# Set the working directory | ||
WORKDIR /app | ||
|
||
# Install dependencies | ||
RUN mv /tmp/sample-apps/django-postgres/requirements.txt ./ | ||
RUN pip install -r requirements.txt | ||
|
||
# Build and install aikido_firewall from source | ||
WORKDIR /tmp | ||
RUN pip install poetry | ||
RUN rm -rf ./dist | ||
RUN make build | ||
RUN mv ./dist/aikido_firewall-*.tar.gz ./dist/aikido_firewall.tar.gz | ||
RUN pip install ./dist/aikido_firewall.tar.gz | ||
RUN pip list | ||
|
||
WORKDIR /app |
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,16 @@ | ||
# Sample Django/Postgres App | ||
It runs **multi-threaded** | ||
|
||
## Getting started | ||
With docker-compose installed run | ||
```bash | ||
docker-compose up --build | ||
``` | ||
This will expose a Django web server at [localhost:8094](http://localhost:8094) | ||
|
||
## URLS : | ||
- Homepage : `http://localhost:8094/app` | ||
- Create a dog : `http://localhost:8094/app/create/<dog_name>` | ||
- MySQL attack : `Malicious dog", "Injected wrong boss name"); -- ` | ||
|
||
To verify your attack was successfully note that the boss_name usualy is 'N/A', if you open the dog page (you can do this from the home page). You should see a "malicious dog" with a boss name that is not permitted. |
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,26 @@ | ||
version: "3" | ||
services: | ||
backend_firewall_disabled: | ||
image: sample_django_mysql | ||
command: sh -c "python3 manage.py migrate --noinput && python manage.py runserver 0.0.0.0:8000" | ||
restart: always | ||
volumes: | ||
- .:/app | ||
ports: | ||
- "8095:8000" | ||
depends_on: | ||
- db | ||
extra_hosts: | ||
- "app.local.aikido.io:host-gateway" | ||
environment: | ||
FIREWALL_DISABLED: 1 | ||
SECRET_KEY: 'Test key' | ||
DB_HOST: 'db' | ||
DB_NAME: 'db' | ||
DB_USER: 'user' | ||
DB_PASSWORD: 'password' | ||
backend: | ||
environment: | ||
AIKIDO_TOKEN: "test_aikido_token" | ||
AIKIDO_BLOCKING: 1 | ||
|
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,50 @@ | ||
version: '3' | ||
services: | ||
db: | ||
image: postgres:14-alpine | ||
container_name: django_postgres_db | ||
restart: always | ||
volumes: | ||
- db_data:/var/lib/postgresql/data | ||
environment: | ||
POSTGRES_DB: 'db' | ||
POSTGRES_USER: 'user' | ||
POSTGRES_PASSWORD: 'password' | ||
ports: | ||
- "5432:5432" | ||
networks: | ||
- default_network | ||
|
||
backend: | ||
image: sample_django_postgres | ||
build: | ||
context: ./../../ | ||
dockerfile: ./sample-apps/django-postgres/Dockerfile | ||
container_name: django_postgres_backend | ||
command: sh -c "python3 manage.py migrate --noinput && python manage.py runserver 0.0.0.0:8000" | ||
restart: always | ||
volumes: | ||
- .:/app | ||
ports: | ||
- "8094:8000" | ||
depends_on: | ||
- db | ||
networks: | ||
- default_network | ||
extra_hosts: | ||
- "app.local.aikido.io:host-gateway" | ||
environment: | ||
SECRET_KEY: 'Test key' | ||
DB_HOST: 'db' | ||
DB_NAME: 'db' | ||
DB_USER: 'user' | ||
DB_PASSWORD: 'password' | ||
FIREWALL_DISABLED: 0 | ||
|
||
|
||
volumes: | ||
db_data: | ||
|
||
networks: | ||
default_network: | ||
driver: bridge |
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,31 @@ | ||
#!/usr/bin/env python | ||
"""Django's command-line utility for administrative tasks.""" | ||
from dotenv import load_dotenv | ||
import os | ||
load_dotenv() | ||
firewall_disabled = os.getenv("FIREWALL_DISABLED") | ||
if firewall_disabled is not None: | ||
if firewall_disabled.lower() != "1": | ||
import aikido_firewall # Aikido package import | ||
aikido_firewall.protect() | ||
|
||
import os | ||
import sys | ||
|
||
|
||
def main(): | ||
"""Run administrative tasks.""" | ||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sample-django-postgres-app.settings') | ||
try: | ||
from django.core.management import execute_from_command_line | ||
except ImportError as exc: | ||
raise ImportError( | ||
"Couldn't import Django. Are you sure it's installed and " | ||
"available on your PYTHONPATH environment variable? Did you " | ||
"forget to activate a virtual environment?" | ||
) from exc | ||
execute_from_command_line(sys.argv) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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,4 @@ | ||
django | ||
python-decouple | ||
cryptography | ||
psycopg2-binary |
Empty file.
16 changes: 16 additions & 0 deletions
16
sample-apps/django-postgres/sample-django-postgres-app/asgi.py
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,16 @@ | ||
""" | ||
ASGI config for sample-django-postgres-app project. | ||
It exposes the ASGI callable as a module-level variable named ``application``. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.asgi import get_asgi_application | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'sample-django-postgres-app.settings') | ||
|
||
application = get_asgi_application() |
Oops, something went wrong.