-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathapi.py
executable file
·75 lines (61 loc) · 1.97 KB
/
api.py
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
69
70
71
72
73
74
75
import json
import os
import sys
import requests
from flask import Flask, request
currentdir = os.path.dirname(os.path.realpath(__file__))
parentdir = os.path.dirname(currentdir)
sys.path.append(parentdir)
import re
import alert
import FlaskApp.database
from checkdefaced import check
from screenshot import screenshot
def slug(string):
pattern = "|%[0-9]{1,}|%|--|#|;|/\*|'|\"|\\\*|\[|\]|xp_|\>|\&ne|\<|&"
result = re.sub(pattern, "", string)
return result
app = Flask(__name__)
@app.route("/checkdeface", methods=["POST"])
def checkdeface():
db = FlaskApp.database.Database("site")
al = alert.Alert()
res = {}
body = json.loads(request.data)
if len(body["key"]) == 0 and len(body["path"]) == 0:
res = {"status": "400 Bad Request!"}
return res
else:
key = slug(body["key"])
active_key = {"active_key": key}
data = db.get_single_data(active_key)
if data is None:
res = {"status": "404 Key Invalid!"}
return res
url = data["url"] + body["path"]
receiver = data["email"]
try:
response = requests.get(url)
except requests.ConnectionError:
res = {"status": "500 Internal Server Error!"}
return res
if (response.status_code != 200) and (response.status_code != 302):
res = {"status": "URL Invalid! " + url}
else:
img_path = screenshot(url)
defaced = check(img_path)
if defaced:
al.sendBot(url, img_path)
subject = "Website Defacement"
message = (
f"You website was defaced!\nURL: {url} \nPath infected: {body['path']}"
)
al.sendMessage(receiver, subject, message, img_path)
res = {"status": "Website was defaced!"}
print("Website was defaced!")
else:
res = {"status": "Everything oke!"}
print("Everything oke!")
return res
if __name__ == "__main__":
app.run(host="0.0.0.0", port="8088")