-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathsender.py
36 lines (26 loc) · 1.1 KB
/
sender.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
import requests as req
import logging
import brotli
import time
from config import config
logger = logging.getLogger("Sender")
def scannerDetectsBytes(data: bytes, filename: str, useBrotli=True, verify=False, no_exec=False):
if config.get("avred_server") == "":
logging.error("No AVRed server configured, aborting")
return
params = { 'filename': filename, 'brotli': useBrotli, 'verify': verify, 'no_exec' : no_exec}
if useBrotli:
scanData = brotli.compress(data)
else:
scanData = data
timeStart = time.time()
logger.info("Send to exec/exe: {}".format(params))
res = req.post("{}/exec/exe".format(config.get("avred_server")), params=params, data=scanData, timeout=10)
jsonRes = res.json()
scanTime = round(time.time() - timeStart, 3)
logger.info("Response: {}s: {}".format(scanTime, jsonRes))
# basically internal server error, e.g. AMSI not working
if res.status_code != 200:
logging.error("Error Code {}: {}".format(res.status_code, res.text))
raise Exception("Server error, aborting")
return jsonRes