Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc8d3aa7

Browse files
committed
Adding OWASP-Top10 Sample App
1 parentef04b8d commitc8d3aa7

File tree

24 files changed

+18545
-0
lines changed

24 files changed

+18545
-0
lines changed

‎owasp-top10/.env‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
MONGODB_URI=mongodb://localhost:27017
2+

‎owasp-top10/.gitignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
venv/

‎owasp-top10/README.md‎

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#Educational Vulnerable Application
2+
3+
**WARNING: This application is intentionally vulnerable and meant for educational purposes only. DO NOT deploy this in any production environment.**
4+
5+
##Overview
6+
This application demonstrates common security vulnerabilities based on OWASP Top 10 (2021). It consists of two microservices:
7+
- Auth Service: Handles user authentication with intentional vulnerabilities
8+
- Profile Service: Manages user profile data with intentional vulnerabilities
9+
10+
##Intentional Vulnerabilities
11+
12+
###1. Broken Access Control (A01:2021)
13+
- No role-based access control implementation
14+
- Direct object references without verification
15+
- Location:`auth_service/routes.py` - endpoint`/api/user/<id>`
16+
17+
###2. Cryptographic Failures (A02:2021)
18+
- Passwords stored with weak hashing (MD5)
19+
- Sensitive data transmitted without encryption
20+
- Location:`auth_service/utils.py` -`hash_password()` function
21+
22+
###3. Injection (A03:2021)
23+
- SQL injection vulnerability in login query
24+
- NoSQL injection in profile lookup
25+
- Location:`auth_service/routes.py` -`/login` endpoint
26+
- Location:`profile_service/routes.py` -`/profile` endpoint
27+
28+
###4. Insecure Design (A04:2021)
29+
- No rate limiting on login attempts
30+
- Password reset without verification
31+
- Location:`auth_service/routes.py` - all endpoints
32+
33+
###5. Security Misconfiguration (A05:2021)
34+
- Debug mode enabled
35+
- Default/weak credentials
36+
- Location:`config.py` - all configuration settings
37+
38+
###6. Vulnerable Components (A06:2021)
39+
- Outdated dependencies in requirements.txt
40+
- Known vulnerable versions of packages
41+
42+
###7. Authentication Failures (A07:2021)
43+
- Weak password requirements
44+
- Session tokens without expiry
45+
- Location:`auth_service/utils.py` -`validate_password()` function
46+
47+
###8. Software and Data Integrity Failures (A08:2021)
48+
- No integrity checks on uploaded files
49+
- Unsecured deserialization
50+
- Location:`profile_service/routes.py` -`/upload` endpoint
51+
52+
###9. Security Logging Failures (A09:2021)
53+
- No logging of security events
54+
- Sensitive data in logs
55+
- Location: Both services lack proper logging
56+
57+
###10. Server-Side Request Forgery (A10:2021)
58+
- Unvalidated URL inputs
59+
- Location:`profile_service/routes.py` -`/fetch-avatar` endpoint
60+
61+
##Setup Instructions
62+
63+
1. Create virtual environment:
64+
```bash
65+
python -m venv venv
66+
source venv/bin/activate# Linux/Mac
67+
venv\Scripts\activate# Windows
68+
```
69+
70+
2. Install dependencies:
71+
```bash
72+
pip install -r requirements.txt
73+
```
74+
75+
3. Set up MongoDB:
76+
- Use local MongoDB instance or
77+
- Create free MongoDB Atlas cluster
78+
79+
4. Configure environment:
80+
```bash
81+
cp .env.example .env
82+
# Edit .env with your MongoDB URI
83+
```
84+
85+
5. Run services:
86+
```bash
87+
# Terminal 1
88+
python auth_service/app.py
89+
90+
# Terminal 2
91+
python profile_service/app.py
92+
```
93+
94+
##Testing Vulnerabilities
95+
96+
1. SQL Injection:
97+
```
98+
Username: admin' OR '1'='1
99+
Password: anything
100+
```
101+
102+
2. NoSQL Injection:
103+
```javascript
104+
{"$gt":""}in username field
105+
```
106+
107+
3. Weak Passwords:
108+
```
109+
Any password with length > 1 is accepted
110+
```
111+
112+
4. SSRF Test:
113+
```
114+
/fetch-avatar?url=file:///etc/passwd
115+
```
116+
117+
##Automated Testing
118+
Run security scanners againsthttp://localhost:5000 andhttp://localhost:5001 to detect vulnerabilities.
119+
120+
##Disclaimer
121+
This application is for educational purposes only. It contains intentional security vulnerabilities to demonstrate common security issues. DO NOT use any of this code in production environments.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Dockerfile for auth-service
2+
FROM node:14
3+
4+
WORKDIR /app
5+
COPY package.json package-lock.json ./
6+
RUN npm install
7+
8+
COPY . .
9+
CMD ["node","server.js"]
874 Bytes
Binary file not shown.

‎owasp-top10/auth_service/app.py‎

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
fromflaskimportFlask,request,jsonify
2+
fromflask_corsimportCORS
3+
fromutilsimporthash_password,generate_token
4+
importsqlite3
5+
importjson
6+
7+
app=Flask(__name__)
8+
9+
# Enable CORS for all routes
10+
CORS(app)
11+
12+
app.config['DEBUG']=True
13+
app.secret_key='xuysoe54Puj990'
14+
15+
@app.route('/',methods=['GET'])
16+
defentry():
17+
returnjsonify({"error":"Invalid credentials"}),401
18+
19+
@app.route('/login',methods=['POST'])
20+
deflogin():
21+
data=request.get_json()
22+
username=data.get('username')
23+
password=data.get('password')
24+
25+
# Verify user credentials (hash password comparison)
26+
query=f"SELECT * FROM users WHERE username='{username}' AND password='{hash_password(password)}'"
27+
conn=sqlite3.connect('users.db')
28+
cursor=conn.cursor()
29+
user=cursor.execute(query).fetchone()
30+
31+
ifuser:
32+
# Generate JWT token
33+
token=generate_token(username)
34+
35+
# Decode token to string and return
36+
returnjsonify({"token":token.decode('utf-8')})
37+
returnjsonify({"error":"Invalid credentials"}),401
38+
39+
40+
@app.route('/register',methods=['POST'])
41+
defregister():
42+
data=request.get_json()
43+
44+
iflen(data.get('password',''))>1:
45+
hashed_password=hash_password(data['password'])
46+
47+
# Create connection to SQLite database
48+
conn=sqlite3.connect('users.db')
49+
cursor=conn.cursor()
50+
51+
# Ensure the users table is created if it does not exist
52+
cursor.execute('''
53+
CREATE TABLE IF NOT EXISTS users (
54+
id INTEGER PRIMARY KEY AUTOINCREMENT,
55+
username TEXT UNIQUE NOT NULL,
56+
password TEXT NOT NULL
57+
)
58+
''')
59+
60+
try:
61+
# Use parameterized queries to prevent SQL injection
62+
cursor.execute(
63+
'INSERT INTO users (username, password) VALUES (?, ?)',
64+
(data['username'],hashed_password)
65+
)
66+
conn.commit()
67+
returnjsonify({"message":"User registered successfully"})
68+
exceptsqlite3.IntegrityError:
69+
70+
# Handle unique constraint violation (duplicate username)
71+
returnjsonify({"error":"Username already exists"}),400
72+
finally:
73+
conn.close()
74+
else:
75+
returnjsonify({"error":"Invalid password"}),400
76+
77+
@app.route('/api/user/<id>',methods=['GET'])
78+
defget_user(id):
79+
conn=sqlite3.connect('users.db')
80+
cursor=conn.cursor()
81+
user=cursor.execute(f"SELECT * FROM users WHERE id={id}").fetchone()
82+
83+
ifuser:
84+
returnjsonify({
85+
"id":user[0],
86+
"username":user[1],
87+
"password_hash":user[2]
88+
})
89+
returnjsonify({"error":"User not found"}),404
90+
91+
if__name__=='__main__':
92+
app.run(port=5000,debug=True)

‎owasp-top10/auth_service/utils.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
importhashlib
2+
importjwt
3+
4+
defhash_password(password):
5+
returnhashlib.md5(password.encode()).hexdigest()
6+
7+
defgenerate_token(username):
8+
returnjwt.encode(
9+
{'username':username},
10+
'xuysoe54Puj990',
11+
algorithm='HS256'
12+
)
13+
14+
defvalidate_password(password):
15+
returnlen(password)>1

‎owasp-top10/docker-compose.yml‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
version:'3.8'
2+
services:
3+
frontend:
4+
build:
5+
context:./frontend
6+
dockerfile:Dockerfile
7+
ports:
8+
-"3000:3000"
9+
environment:
10+
-REACT_APP_AUTH_SERVICE_URL=http://auth-service:5000
11+
-REACT_APP_PROFILE_SERVICE_URL=http://profile-service:5001
12+
depends_on:
13+
-auth-service
14+
-profile-service
15+
auth-service:
16+
build:
17+
context:./auth_service
18+
dockerfile:Dockerfile
19+
ports:
20+
-"5000:5000"
21+
environment:
22+
-MONGO_URI=mongodb://mongo:27017/
23+
depends_on:
24+
-mongo
25+
profile-service:
26+
build:
27+
context:./profile_service
28+
dockerfile:Dockerfile
29+
ports:
30+
-"5001:5001"
31+
environment:
32+
-MONGO_URI=mongodb://mongo:27017/
33+
depends_on:
34+
-mongo
35+
mongo:
36+
image:mongo:4.4
37+
ports:
38+
-"27017:27017"
39+
volumes:
40+
-mongodb_data:/data/db
41+
volumes:
42+
mongodb_data:

‎owasp-top10/frontend/Dockerfile‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Dockerfile for frontend
2+
FROM node:14
3+
4+
WORKDIR /app
5+
COPY package.json package-lock.json ./
6+
RUN npm install
7+
8+
COPY . .
9+
RUN npm run build
10+
11+
CMD ["npm","start"]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp