-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathreddrop-server.py
72 lines (54 loc) · 2.28 KB
/
reddrop-server.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
from logging import DEBUG
import gunicorn.app.base
from confuse.exceptions import NotFoundError
import reddrop.authorization
from reddrop.app import app
from reddrop.config import ConfigTemplate, config
from reddrop.args import parse_arguments
from reddrop.logger import prettyPrintFormatString
class RedDropApplication(gunicorn.app.base.BaseApplication):
"""
The Gunicorn Application Base for Red Drop:
https://docs.gunicorn.org/en/stable/custom.html#custom-application
"""
def __init__(self, app, options=None):
self.options = options or {}
self.application = app
super().__init__()
def load_config(self):
config = {key: value for key, value in self.options.items()
if key in self.cfg.settings and value is not None}
for key, value in config.items():
self.cfg.set(key.lower(), value)
def load(self):
return self.application
if __name__ == "__main__":
import sys
args = parse_arguments()
if args.config:
config.set_file(args.config)
config.set_args(args, dots=True)
if len(args.process_list) > 0:
prettyPrintFormatString('{{ c("yellow", "[!] The following processing list has been set, turning off auto_process: ") }}{{process_list}}', {"process_list": args.process_list})
config['auto_process'].set(False)
if args.dump_config:
print(config.dump())
sys.exit()
try:
config.get(ConfigTemplate)
except NotFoundError as e:
app.logger.error(f'The configuration file provided is invalid, please fix: {e}')
sys.exit()
if args.authorization_rules:
# We must recompile the authorization rules here as they have already been compiled at load time
reddrop.authorization.compiled_rules = reddrop.authorization.compileRules()
if config['debug'].get():
app.logger.setLevel(DEBUG
)
app.run(config['host'].get(), port=config['port'].get(), debug=config['debug'].get())
else:
app.logger.info("Starting RedDrop Exfil Server")
options = config['gunicorn'].get()
options.update(config['gunicorn']['defaults'].get())
options['bind'] = f'{config["host"].get()}:{config["port"].get()}'
RedDropApplication(app, options).run()