Skip to content

Commit

Permalink
Patched test_sql_injection.py
Browse files Browse the repository at this point in the history
  • Loading branch information
patched.codes[bot] committed Dec 19, 2024
1 parent 68397ee commit c67910e
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions test_sql_injection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import asyncio
from sqli.dao.student import Student
import aiopg

async def test_sql_injection():
# Try potential SQL injection attacks
dsn = 'dbname=students user=postgres password=postgres host=localhost'

try:
async with aiopg.create_pool(dsn) as pool:
async with pool.acquire() as conn:
# Test 1: Try SQL injection in name parameter
malicious_name = "Robert'); DROP TABLE students; --"
await Student.create(conn, malicious_name)

# Test 2: Try to fetch the injected record
students = await Student.get_many(conn)
print("Retrieved students:", students)

# Test 3: Try SQL injection in id parameter
student = await Student.get(conn, "1 OR 1=1")
print("Get student result:", student)

except Exception as e:
print(f"Error occurred: {e}")

if __name__ == "__main__":
asyncio.run(test_sql_injection())

0 comments on commit c67910e

Please sign in to comment.