Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. from flask import *
  2. from ml import *
  3. import pymysql.cursors
  4. connection = pymysql.connect(host='127.0.0.1',
  5. user='',
  6. password='',
  7. db='ctf',
  8. charset='utf8mb4',
  9. cursorclass=pymysql.cursors.DictCursor)
  10. app = Flask(__name__)
  11. global ML
  12. ML = WAF_ML(mode="load")
  13. ML.train()
  14. print ("done")
  15. def log(path):
  16. with open('log.txt','a') as f:
  17. f.write(path + '\n')
  18. @app.route('/<path:path>')
  19. def index(path):
  20. path = request.full_path
  21. print (request.path)
  22. path = str(urllib.parse.unquote(path))
  23. path = list(preProcessing([path]))
  24. result = 0
  25. if len(path) > 0:
  26. path = path[0]
  27. path_split = []
  28. while len(path) >= 15:
  29. path_split.append(path[:15])
  30. path = path[13:]
  31. if len(path) >= 3:
  32. path_split.append(path)
  33. if len(request.path) >= 3:
  34. path_split.append(request.path)
  35. print (path_split)
  36. test = ML.vectorizer.transform(path_split)
  37. predict = ML.lgs.predict(test)
  38. print (predict)
  39. result = 0
  40. for p in predict:
  41. result |= p
  42. if result == 0:
  43. try:
  44. with connection.cursor() as cursor:
  45. sql = "SELECT * FROM test WHERE id=" + request.args.get('id')
  46. print (sql)
  47. cursor.execute(sql)
  48. result = cursor.fetchone()
  49. return result['desc']
  50. except Exception as e:
  51. print (e)
  52. return "Nope"
  53. return "Nope"
  54. from gevent.wsgi import WSGIServer
  55. if __name__ == "__main__":
  56. server = WSGIServer(('0.0.0.0',80),app)
  57. server.serve_forever()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement