Skip to content

Commit 27abf1f

Browse files
authored
Merge branch 'adeyosemanputra:master' into insec_des_lab
2 parents da0353e + 7bb76db commit 27abf1f

7 files changed

Lines changed: 205 additions & 27 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ venv
77
*db.sqlite3*
88
app.log
99
bin
10-
10+
*.env
1111

1212
# LOG files
1313
*.log

CHANGELOG.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Pygoat v2.0.2 snapshot
2+
### 1.Added
3+
- **Custom Management Command:**
4+
Added the `populate_challenges` command that reads challenge data from `challenge/challenge.json` and populates the `Challenge` table using `get_or_create` to prevent duplicate entries. The command handles missing files and JSON decode errors gracefully.
5+
- Added `MIT License` to the project.
6+
7+
### 2.Changed
8+
- **Challenge Model:**
9+
- Updated the `save()` method to raise a `ValidationError` if `start_port` is greater than `end_port`.
10+
- Enhanced flag handling by hashing the `flag` field using SHA-256 (prefixed with "hashed_") if it hasn't been hashed already.
11+
12+
---
13+
14+
# Pygoat v2.0.1 Latest
15+
16+
1. New themes
17+
2. Bug fixing
18+
19+
---
20+
21+
# PyGoat V2.0.0
22+
23+
PyGoat Release Version 2.0.0
24+
25+
* Whole new section for OWASP TOP 10 2021
26+
i. New lab on template injection
27+
ii. New 3 labs on cryptographic failure
28+
iii. 1 more lab on broken access control
29+
iv. 1 lab on Insecure Design
30+
v. 1 more lab on security misconfiguration
31+
vi. 1 new lab on using components with known vulnerability
32+
vii. 2 new labs on Identification and Authentication failure
33+
viii. 1 lab on software and data integrity failure and XXS
34+
ix. Some labs on Insufficient logging
35+
x. 2 new labs on SSRF
36+
37+
* Section for Code discussion for most of the sections of OWASP 2021
38+
39+
* Coding playground for SSRF
40+
i. Authentication failure
41+
ii. Insufficient logging
42+
43+
* Added new section for SANS 25 and MITRE 25
44+
45+
* Added new lab in SANS and MITRE 25 section
46+
i. Path traversal
47+
ii. Command injection
48+
iii. Code injection
49+
iv. CSRF
50+
51+
* New Dark theme and improved UI
52+
53+
* Better Docker file for smooth install
54+
55+
* Brand new Logo
56+
57+
---
58+
59+
# v2.0
60+
61+
PyGoat Pre-Release Version 2.0
62+
63+
* Whole new section for OWASP TOP 10 2021
64+
i. New lab on template injection
65+
ii. New 3 labs on cryptographic failure
66+
iii. 1 more lab on broken access control
67+
iv. 1 lab on Insecure Design
68+
v. 1 more lab on security misconfiguration
69+
vi. 1 new lab on using components with known vulnerability
70+
vii. 2 new labs on Identification and Authentication failure
71+
viii. 1 lab on software and data integrity failure and XXS
72+
ix. Some labs on Insufficient logging
73+
x. 2 new labs on SSRF
74+
75+
* Section for Code discussion for most of the sections of OWASP 2021
76+
77+
* Coding playground for
78+
- SSRF
79+
i. Authentication failure
80+
ii. Insufficient logging
81+
82+
* Added new section for SANS 25 and MITRE 25
83+
84+
* Added new lab in SANS and MITRE 25 section
85+
i. Path traversal
86+
ii. Command injection
87+
iii. Code injection
88+
iv. CSRF
89+
90+
* New Dark theme and improved UI
91+
92+
* Better Docker file for smooth install
93+
94+
* Brand new Logo
95+
96+
---
97+
98+
# Pygoat Gibraltar v1.2
99+
100+
i. Fix [#57](https://github.com/adeyosemanputra/pygoat/pull/57) Fix Path Error
101+
ii. Fix [#55](https://github.com/adeyosemanputra/pygoat/pull/55) Added Google OAuth / Auth with Google
102+
iii. Fix [#54](https://github.com/adeyosemanputra/pygoat/pull/54) Change Login
103+
104+
---
105+
106+
# Pygoat Gibraltar v1.1
107+
108+
i. Added Authentication For LAB [#43](https://github.com/adeyosemanputra/pygoat/pull/43)
109+
ii. Fix For A10 Insufficient Logging & Monitoring
110+
111+
---
112+
113+
# Pygoat Gibraltar v1.0
114+
115+
Added vulns done:
116+
i. A1:2017-Injection
117+
ii. A2:2017-Broken Authentication
118+
iii. A3:2017-Sensitive Data Exposure
119+
iv. A4:2017-XML External Entities (XXE)
120+
v. A5:2017-Broken Access Control
121+
vi. A6:2017-Security Misconfiguration
122+
vii. A7:2017-Cross-Site Scripting (XSS)
123+
viii. A8:2017-Insecure Deserialization
124+
ix. A9:2017-Using Components with Known Vulnerabilities
125+
x. A10:2017-Insufficient Logging & Monitoring

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 pygoat
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import json
2+
import os
3+
from django.core.management.base import BaseCommand
4+
from challenge.models import Challenge
5+
6+
class Command(BaseCommand):
7+
help = (
8+
"Reads challenge data from 'challenge/challenge.json' and populates the "
9+
"Challenge table in the database. Uses get_or_create to prevent duplicates "
10+
"and handles JSON errors gracefully."
11+
)
12+
13+
def handle(self, *args, **options):
14+
file_path = os.path.join('challenge', 'challenge.json')
15+
16+
try:
17+
with open(file_path, 'r') as json_file:
18+
challenges_data = json.load(json_file)
19+
except FileNotFoundError:
20+
self.stderr.write(self.style.ERROR(f"JSON file not found: {file_path}"))
21+
return
22+
except json.JSONDecodeError as e:
23+
self.stderr.write(self.style.ERROR(f"Error decoding JSON: {e}"))
24+
return
25+
26+
for item in challenges_data:
27+
challenge, created = Challenge.objects.get_or_create(
28+
name=item.get("name"),
29+
defaults={
30+
"description": item.get("description", ""),
31+
"docker_image": item.get("docker_image", ""),
32+
"docker_port": item.get("docker_port", 0),
33+
"start_port": item.get("start_port", 0),
34+
"end_port": item.get("end_port", 0),
35+
"flag": item.get("flag", ""),
36+
"point": item.get("point", 0)
37+
}
38+
)
39+
if created:
40+
self.stdout.write(self.style.SUCCESS(f"Challenge '{challenge.name}' created."))
41+
else:
42+
self.stdout.write(f"Challenge '{challenge.name}' already exists.")
43+
44+
self.stdout.write(self.style.SUCCESS("Challenge data has been populated successfully."))

challenge/models.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from django.db import models
22
from django.contrib.auth.models import User
3+
import hashlib # Import hashlib
4+
from django.core.exceptions import ValidationError # Import ValidationError
35

4-
# Create your models here
56
class Challenge(models.Model):
67
id = models.AutoField(primary_key=True, unique=True)
78
name = models.CharField(max_length=100, unique=True)
@@ -18,11 +19,13 @@ class Challenge(models.Model):
1819
def __str__(self):
1920
return self.name
2021

21-
# overwriting default save method
22+
# Overriding default save method
2223
def save(self, *args, **kwargs):
2324
if self.start_port > self.end_port:
24-
raise Exception("Start port should be less than end port")
25-
# Here flag need to be hashed
25+
raise ValidationError("Start port should be less than end port") # Raise ValidationError if start_port is greater than end_port
26+
if self.flag:
27+
if not self.flag.startswith("hashed_"):
28+
self.flag = "hashed_" + hashlib.sha256(self.flag.encode('utf-8')).hexdigest()
2629
super(Challenge, self).save(*args, **kwargs)
2730

2831
class UserChallenge(models.Model):
@@ -40,7 +43,6 @@ class UserChallenge(models.Model):
4043
is_live = models.BooleanField(default=False)
4144
no_of_attempt = models.IntegerField(default=0)
4245
is_solved = models.BooleanField(default=False)
43-
port = models.IntegerField()
4446

4547
def __str__(self):
46-
return f"{self.user.username} - {self.challenge.name}"
48+
return f"{self.user.username} - {self.challenge.name}"

docker-compose.yml

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,15 @@
1-
version: "3.3"
2-
31
services:
4-
db:
5-
image: postgres
6-
volumes:
7-
- ./data/db:/var/lib/postgresql/data
8-
environment:
9-
- POSTGRES_DB=postgres
10-
- POSTGRES_USER=postgres
11-
- POSTGRES_PASSWORD=postgres
122
web:
133
build: .
14-
image: pygoat/pygoat
154
command: gunicorn --bind 0.0.0.0:8000 --workers 6 pygoat.wsgi
165
ports:
176
- "8000:8000"
187
volumes:
198
- .:/app
209
depends_on:
2110
- migration
22-
- db
2311
migration:
24-
image: pygoat/pygoat
25-
command: python pygoat/manage.py migrate --noinput
12+
image: pygoat/pygoat:latest
13+
command: python manage.py migrate --noinput
2614
volumes:
27-
- .:/app
28-
depends_on:
29-
- db
15+
- .:/app

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ certifi==2022.12.7
55
cffi==1.15.1
66
charset-normalizer==3.0.1
77
cryptography==39.0.1
8-
crispy_bootstrap4
8+
crispy-bootstrap4===2024.10
99
defusedxml==0.7.1
1010
dj-database-url==0.5.0
11-
Django==4.1.7
11+
Django==4.2
1212
django-allauth==0.52.0
13-
django-crispy-forms==2.0
13+
django-crispy-forms==2.3
1414
django-heroku==0.3.1
1515
gunicorn==23.0.0
1616
idna==3.4

0 commit comments

Comments
 (0)