EvanAuth is a brand new startup out of UC Berkeley offering an authentication system. Unfortunately, their new intern has made a mistake and created a SQL injection vulnerability which will allow any user to change another user's password! Your goal is to change the admin account's password to a known value so you can log into it.
-
Create a virtualenv:
python3 -m venv .161venv -
Activate the virtualenv:
- On Mac:
source .161venv/bin/activate - On Windows:
.\161venv\Scripts\activate
- On Mac:
-
Update
pipwithpython3 -m pip install --upgrade pip. -
Install the Python requirements:
pip install -r requirements.txt -
Run the server with
./server.sh
-
Follow the instructions above to set up and run the server locally.
-
Navigate to http://127.0.0.1:5000 and poke around the website a little. Note: everytime you restart the server it resets the database to its original state!
-
Figure out the SQL Injection vulnerability! Your goal is to log into the account with the username "admin". As you complete the SQL injection, note down the various inputs you fed into the website so you can use them for step 4. (Hint: since the source code is open to you it will be helpful to look into it. Check out
main.pywhich has the relevant functions marked with a comment, as well asschema.sqlfor the DB table setup). It may also be helpful to read up on query parameterization insqlite3. -
Place your inputs in order in the
input.infile following the example inexample_input.in. The first item on every line should be eitherCreate_Account,Login,Initiate_Reset, orResetand determines what call to make to the server based on the 4 types of inputs in the website (Initiate_Resetcorresponds to the form on the homepage andResetcorresponds to the actual reset password form). Arguments come after and are separated with the|character. Do not include the|character in any of your arguments (it's not necessary to use it anywhere). To see what arguments each option takes look atexample_input.in. -
To test your solution: rerun the server via
./server.shto reset its database, then leave it running and open a second terminal window to runpython3 grader.py
It may be difficult to visualize the results of your injected query. To do this we would recommend adding in a print statement after the relevant conn.execute statement in main.py to print its output. Make sure to rerun the server when you do this so your changes will be reflected.
You can also test SQL queries on the database directly as follows:
- Open a new terminal window and activate the
venvby following step 2 in Setup + Running. - Run
python3 - In the interpreter that opens run something similar to the following to execute a query:
>>> import sqlite3
>>> conn = sqlite3.connect('database.db')
>>> conn.row_factory = sqlite3.Row
>>> res = conn.execute("SELECT username from users").fetchall()
>>> res[0]['username']
'admin'
```# SQL Injection Web Lab
# 程序代做代写 CS编程辅导
# WeChat: cstutorcs
# Email: tutorcs@163.com
# CS Tutor
# Code Help
# Programming Help
# Computer Science Tutor
# QQ: 749389476