-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
68 lines (54 loc) · 1.72 KB
/
Copy pathserver.py
File metadata and controls
68 lines (54 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from flask import Flask, request, jsonify
import sqlite3
app = Flask(__name__)
# output to file
file_path = 'output.txt'
file = open(file_path, 'a')
# output to db
DB = 'my_database.db'
CONN = sqlite3.connect(DB)
CURSOR = CONN.cursor()
CURSOR.execute('''
CREATE TABLE IF NOT EXISTS my_table (
id INTEGER PRIMARY KEY,
parameter TEXT
)
''')
CONN.close()
@app.route('/bin', methods=['POST'])
def receive_post():
try:
post_data = request.get_json()
id_value = post_data['id']
# Write the 'id' parameter to the file
if id_value:
file.write(str(id_value) + '\n' )
# print(file)
# print(id_value)
file.flush()
response_message = {'message': 'ID parameter written to file.'}
return jsonify(response_message), 200
except Exception as e:
print(str(e))
return jsonify({'error': str(e)}), 400
@app.route('/sqli', methods=['POST'])
def receive_sqli():
try:
post_data = request.get_json()
id_value = post_data['id']
# Write the 'id' parameter to the db
if id_value:
conn = sqlite3.connect(DB)
cursor = conn.cursor()
# cursor.execute('INSERT INTO my_table (parameter) VALUES ('+id_value+')')
cursor.execute("INSERT INTO my_table (parameter) VALUES ('{}');".format(id_value))
conn.commit()
conn.close()
# print(id_value)
response_message = {'message': 'ID parameter written to db.'}
return jsonify(response_message), 200
except Exception as e:
print(str(e))
return jsonify({'error': str(e)}), 400
if __name__ == '__main__':
app.run(host='127.0.0.1', port=4444)