With the table now created, you can paste the following for your insert statements:
Listing 2: SQL
INSERT INTO Users VALUES(1,'jess', 'Jess', 'Adams', '86.4', 'Castle', 4.21);
INSERT INTO Users VALUES(2,'greg7', 'Greg', 'Courier', '62', 'Chads', 0);
INSERT INTO Users VALUES(3,'alice4', 'Alice', 'Smith', '57.9', 'Castle', 1.21);
INSERT INTO Users VALUES(4,'chrzi', 'Chris', 'Jackson', '73.8', 'Cuths', 5.33);
INSERT INTO Users VALUES(5,'lauran3', 'Laura', 'Walker', '21.2','Ustinov', 0.34);
INSERT INTO Users VALUES(6,'ai219', 'Andrea', 'Ivanov', '84.2', 'Ustinov', 0.92);
INSERT INTO Users VALUES(7,'seb123', 'Seb', 'Elbert', '17.3', 'Chads', 0);
SELECT
*
FROM Users;
(g) Also, create a ‘Private’ table with the following data, where ID is a primary key and UserID is a
foreign key. Store the wallets as NVARCHAR(80):
ID UserID Wallet
1 3 KworuAjAtnxPhZARLzAadg9WTVKjY4kckS8pw38JrD33CeVYUuDm
2 1 Kwi5LPxVehUieD18AXiXTay9UDkRC7wLShe4tR5kzym1k2NhzEQ6
3 5 L4mGG15YacXWPU7LHM8Lj2LboxabRriZGHFZb5eLDN7mPXPPAHQF
You can use the following for your insert statements:
Listing 3: SQL
INSERT INTO Private VALUES(1, 3, 'KworuAjAtnxPhZARLzAadg9WTVKjY4kckS8pw38JrD33CeVYUuDm');
INSERT INTO Private VALUES(2, 1, 'Kwi5LPxVehUieD18AXiXTay9UDkRC7wLShe4tR5kzym1k2NhzEQ6');
INSERT INTO Private VALUES(3, 5, 'L4mGG15YacXWPU7LHM8Lj2LboxabRriZGHFZb5eLDN7mPXPPAHQF');
(h) Do an inner join on the ‘Users’ and ‘Private’ table data, such that the query result looks like:
Firstname Lastname Wallet
Alice Smith KworuAjAtnxPhZARLzAadg9WTVKjY4kckS8pw38JrD33CeVYUuDm
Jess Adams Kwi5LPxVehUieD18AXiXTay9UDkRC7wLShe4tR5kzym1k2NhzEQ6
Laura Walker L4mGG15YacXWPU7LHM8Lj2LboxabRriZGHFZb5eLDN7mPXPPAHQF
(i) Check that all the data in the database is correct (use the ‘Browse Data’ tab).
(j) Save your statements for creating the tables somewhere for later.
(k) Click ‘Close Database’ and save the changes (write them to ‘secret.db’).
3. SQL injection attacks:
(a) Open the website and do an SQL injection attack on the username input field to get all the ‘Users’
data.
i. Remember ‘−−’ is a comment.
ii. You may wish to study the source code of server.py
4. Prepared statements (parameterized queries):
(a) Fix the server from SQL injection attacks by using parameterized queries.
i. sqlite3 specific guide: https://docs.python.org/2/library/sqlite3.html#sqlite3.
Cursor.execute
(b) Try to do an SQL injection attack again on the username field to confirm that your prepared state-
ments work as expected. Also confirm that you can still ‘login’ as normal users.
5. Inference attacks:
(a) The instructor decides it would be helpful to put some class statistics on the website. The university
has a policy in place where students should not be able to view the grades of other students. In
another part of the website the instructor has a list of students by their college.
(b) Can you infer the grades of each student based on the two views of the data?
i. Just by using the website, what are the grades of Alice, Laura, and Seb?
2