-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added vuln #2
base: main
Are you sure you want to change the base?
added vuln #2
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,71 @@ def sql_injection_login_api(request, app): | |
) | ||
|
||
|
||
def sql_injection_login_apiiiii(request, app): | ||
form = request.form | ||
|
||
username = form.get('username') | ||
password = form.get('password') | ||
password_hash = _hash_password(password) | ||
|
||
sql = f"SELECT * FROM users WHERE username='{username}' AND password='{password_hash}'" | ||
flask.render_template_string(username) | ||
|
||
db_result = app.db_helper.execute_read(sql) | ||
|
||
user = list( | ||
map( | ||
lambda u: { | ||
'id': u[0], | ||
'username': u[1], | ||
'password': u[2] | ||
}, | ||
db_result | ||
) | ||
)[0] if len(db_result) > 0 else None | ||
|
||
return render_template( | ||
'sql_injection/login.html', | ||
sql=sql, | ||
logged=user is not None | ||
) | ||
|
||
|
||
|
||
|
||
|
||
def sql_injection_login_apis(request, app): | ||
form = request.form | ||
|
||
username = form.get('username') | ||
password = form.get('password') | ||
password_hash = _hash_password(password) | ||
|
||
sql = f"SELECT * FROM users WHERE username='{username}' AND password='{password_hash}'" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Detected user input used to manually construct a SQL string. This is usually bad practice because manual construction could accidentally result in a SQL injection. An attacker could use a SQL injection to steal or modify contents of the database. Instead, use a parameterized query which is available by default in most database engines. Alternatively, consider using the Django object-relational mappers (ORM) instead of raw SQL queries. View Dataflow Graphflowchart LR
classDef invis fill:white, stroke: none
classDef default fill:#e7f5ff, color:#1c7fd6, stroke: none
subgraph File0["<b>vulns/sql_injection/sql_injection_login.py</b>"]
direction LR
%% Source
subgraph Source
direction LR
v0["<a href=https://github.com/atearjen/bad-python-app/blob/c06419049f5f898135eeba1c65309a15071249a7/vulns/sql_injection/sql_injection_login.py#L77 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 77] request.form</a>"]
end
%% Intermediate
subgraph Traces0[Traces]
direction TB
v2["<a href=https://github.com/atearjen/bad-python-app/blob/c06419049f5f898135eeba1c65309a15071249a7/vulns/sql_injection/sql_injection_login.py#L77 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 77] form</a>"]
v3["<a href=https://github.com/atearjen/bad-python-app/blob/c06419049f5f898135eeba1c65309a15071249a7/vulns/sql_injection/sql_injection_login.py#L79 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 79] username</a>"]
end
v2 --> v3
%% Sink
subgraph Sink
direction LR
v1["<a href=https://github.com/atearjen/bad-python-app/blob/c06419049f5f898135eeba1c65309a15071249a7/vulns/sql_injection/sql_injection_login.py#L83 target=_blank style='text-decoration:none; color:#1c7fd6'>[Line: 83] f"SELECT * FROM users WHERE username='{username}' AND password='{password_hash}'"</a>"]
end
end
%% Class Assignment
Source:::invis
Sink:::invis
Traces0:::invis
File0:::invis
%% Connections
Source --> Traces0
Traces0 --> Sink
|
||
flask.render_template_string(username) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Found a template created with string formatting. This is susceptible to server-side template injection and cross-site scripting attacks. Ignore this finding from render-template-string. |
||
|
||
db_result = app.db_helper.execute_read(sql) | ||
|
||
user = list( | ||
map( | ||
lambda u: { | ||
'id': u[0], | ||
'username': u[1], | ||
'password': u[2] | ||
}, | ||
db_result | ||
) | ||
)[0] if len(db_result) > 0 else None | ||
|
||
return render_template( | ||
'sql_injection/login.html', | ||
sql=sql, | ||
logged=user is not None | ||
) | ||
|
||
|
||
|
||
|
||
def _hash_password(password): | ||
md5_pass = hashlib.md5(password.encode('utf-8')).hexdigest() | ||
return md5_pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like MD5 is used as a password hash. MD5 is not considered a secure password hash because it can be cracked by an attacker in a short amount of time. Use a suitable password hashing function such as scrypt. You can use
hashlib.scrypt
.View Dataflow Graph
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/semgrep ignore not relevant