Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from flask import *
- from ml import *
- import pymysql.cursors
- connection = pymysql.connect(host='127.0.0.1',
- user='',
- password='',
- db='ctf',
- charset='utf8mb4',
- cursorclass=pymysql.cursors.DictCursor)
- app = Flask(__name__)
- global ML
- ML = WAF_ML(mode="load")
- ML.train()
- print ("done")
- def log(path):
- with open('log.txt','a') as f:
- f.write(path + '\n')
- @app.route('/<path:path>')
- def index(path):
- path = request.full_path
- print (request.path)
- path = str(urllib.parse.unquote(path))
- path = list(preProcessing([path]))
- result = 0
- if len(path) > 0:
- path = path[0]
- path_split = []
- while len(path) >= 15:
- path_split.append(path[:15])
- path = path[13:]
- if len(path) >= 3:
- path_split.append(path)
- if len(request.path) >= 3:
- path_split.append(request.path)
- print (path_split)
- test = ML.vectorizer.transform(path_split)
- predict = ML.lgs.predict(test)
- print (predict)
- result = 0
- for p in predict:
- result |= p
- if result == 0:
- try:
- with connection.cursor() as cursor:
- sql = "SELECT * FROM test WHERE id=" + request.args.get('id')
- print (sql)
- cursor.execute(sql)
- result = cursor.fetchone()
- return result['desc']
- except Exception as e:
- print (e)
- return "Nope"
- return "Nope"
- from gevent.wsgi import WSGIServer
- if __name__ == "__main__":
- server = WSGIServer(('0.0.0.0',80),app)
- server.serve_forever()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement