Skip to content

Commit d7fa2fe

Browse files
committed
Reset Database Function Added!
1 parent 3dab202 commit d7fa2fe

9 files changed

Lines changed: 56 additions & 3 deletions

File tree

.idea/TIWAP.iml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

TIWAF.db

0 Bytes
Binary file not shown.

app.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,16 @@ def settings():
117117

118118
print(session['level'])
119119

120-
return render_template('settings.html', level=level, msg="Difficult Set to " + level)
120+
return render_template('settings.html', level=level, msg="Difficulty Set to " + level)
121121

122+
# Reset DB
123+
@app.route('/reset-db')
124+
@is_logged
125+
def reset_db():
126+
dbm.reset_db()
127+
mongo_dbm.reset_db()
128+
129+
return render_template('settings.html', msg="Database has been reset!")
122130

123131
# SQL Injection
124132
@app.route('/sql-injection', methods=['POST', 'GET'])

helper/db_manager.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,14 @@ def save_name(self, name):
106106
return True
107107

108108
return False
109+
110+
def reset_db(self):
111+
self.create_db_connection()
112+
with open('helper/sqlite_db_reset.txt') as f:
113+
contents = f.readlines()
114+
115+
for content in contents:
116+
self.cur.execute(content)
117+
118+
self.close_db_connection()
119+
self.commit_db()

helper/mongodb_manager.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from pymongo import MongoClient
2+
import pymongo
23

34
# Global Variables
45
client = MongoClient("mongodb://localhost:27017/")
@@ -28,3 +29,20 @@ def get_data_filtered(self, filtered):
2829

2930
except Exception as e:
3031
return e
32+
33+
def reset_db(self):
34+
db = client["TIWAP"]
35+
col_1 = db["cars"]
36+
col_2 = db["users"]
37+
38+
col_1.delete_many({})
39+
col_2.delete_many({})
40+
41+
dict_1 = {"name":"720d", "company":"BMW"}
42+
dict_2 = {'name': 'G63','company': 'AMG'}
43+
dict_3 = {'name': 'A8','company': 'Audi'}
44+
dict_4 = {'username':'admin','password':'admin'}
45+
dict_5 = {'username':'john','password':'john123'}
46+
47+
col_1.insert_many([dict_1,dict_2,dict_3])
48+
col_2.insert_many([dict_4,dict_5])

helper/sqlite_db_reset.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
DROP TABLE comments
2+
DROP TABLE names
3+
CREATE TABLE comments ( comment TEXT )
4+
CREATE TABLE names ( name TEXT )
5+
INSERT INTO comments VALUES('This Project is so cool.')
6+
INSERT INTO comments VALUES('Having Fun with XSS.')
7+
INSERT INTO comments VALUES('This is hacked!')
8+
INSERT INTO names VALUES('Mark')
9+
INSERT INTO names VALUES('Jeff')
10+
INSERT INTO names VALUES('Sundar')

templates/settings.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ <h1 id="vuln-name">Instructions</h1>
7474
</select>
7575
<button class="btn btn-success" type="submit">Set Level</button>
7676
</form>
77+
<form action="/reset-db">
78+
<p><br><b>Reset the Database</b></p>
79+
<button class="btn btn-success" type="submit">Reset DB</button>
80+
</form>
7781
<h6 class="text-center text-muted mt-3">{{ msg }}</h6>
7882
</div>
7983
</div>

0 commit comments

Comments
 (0)