-
Notifications
You must be signed in to change notification settings - Fork 3
/
utilities.py
117 lines (89 loc) · 3 KB
/
utilities.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
from typing import List
import logging
import requests as req
from jinja2 import Template
from pathlib import Path
import yaml
import os
from base64 import b64encode
from model import *
import config
from utilities import *
def getRecipeInfo(file: str, routes: List[AceRoute]):
p = Path(file)
if not p.is_file():
# dont care
return None
with open(file) as f:
yamlData = yaml.safe_load(f)
return RecipeInfo(
name=yamlData['name'],
description=yamlData['description'],
chain=yamlData['chain'],
reference=yamlData['reference'],
binaries=yamlData['binaries'],
modify_filesystem=yamlData['modify_filesystem'],
routes=routes)
def getRecipePyFiles():
res = []
for d in os.listdir('recipes'):
plugin_files = [f for f in os.listdir(os.path.join('recipes', d)) if f.endswith('.py')]
for plugin_file in plugin_files:
if plugin_file == '__init__.py':
continue
res.append(plugin_file)
return res
def yamlHelp(file):
file = file + ".yaml"
p = Path(file)
if not p.is_file():
return
with open(file) as f:
yamlData = yaml.safe_load(f)
#if not 'invalid' in yamlData:
# return
#if not isinstance(yamlData['invalid'], list):
# return
#exceptions = yamlData['invalid']
#for exception in exceptions:
#print("Exceptions: " + str(exceptions))
logging.info("--( Template {}:".format(file))
entries = [ 'title', 'description', 'howtouse', 'input', 'invalid' ]
for key in entries:
if key in yamlData:
logging.info(" {}: {}".format(key, yamlData[key]))
def saveAceFile(file: AceFile):
f = open(file.name, 'wb')
f.write(file.data)
f.close()
logging.info("Written file: {}".format(file.name))
def scanAv(aceFile: AceFile) -> bool:
data = aceFile.data
filename = aceFile.name
params = { 'filename': filename }
if config.ENABLE_SCANNING is False:
return False
url = config.ENABLE_SCANNING
res = req.post(f"{url}/scan", params=params, data=data)
jsonRes = res.json()
if res.status_code != 200:
print("Err: " + str(res.status_code))
print("Err: " + str(res.text))
return False
ret_value = jsonRes['detected']
logging.info("---[ Generating AceFile {}, detected: {}".format(filename, ret_value))
return ret_value
def getTemplate(path: str) -> Template:
with open(path) as f:
template = Template(f.read())
if config.SHOW_TEMPLATE_INFO:
yamlHelp(path)
return template
def replacer(data: bytes, placeholder: bytes, exchange: bytes) -> bytes:
if len(placeholder) != len(exchange):
raise Exception("makeDllExecC2cmd: len not equal, something went wrong: {} {}".format(
len(placeholder), len(exchange)))
if not placeholder in data:
raise Exception("Could not find placeHolder in template")
data = data.replace(placeholder, exchange)
return data