forked from stratosphereips/Ludus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.py
100 lines (84 loc) · 3.28 KB
/
install.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
import os
import configparser
import urllib.request
import random
import string
HASH_SIZE = 32
def colored(text,color):
CRED = '\033[91m'
CEND = '\033[0m'
CGREEN = '\033[92m'
CYELLOW = '\033[93m'
CBLUE = '\033[94m'
if color.lower() == "green":
return CGREEN + text + CEND
elif color.lower() == "red":
return CRED + text + CEND
elif color.lower() == "yellow":
return CYELLOW + text + CEND
elif color.lower() == "blue":
return CBLUE + text + CEND
else:
return text
#update router
if os.system("opkg update") == 0:
print(colored("Router up to date", "green"))
#CHECK DEPENDENCIES
#sentinel
os.system("opkg install python3-msgpack")
os.system("opkg install python3-zmq")
os.system("opkg install sentinel-proxy")
os.system("sentinel_certgen certs --renew")
#start sentinel
os.system("/etc/init.d/sentinel-proxy start")
#suricata
os.system("opkg install suricata-bin")
#tarpit
os.system("opkg install iptables-mod-tarpit")
os.system("opkg install kmod-ipt-tarpit")
#create config file
config_path = "/etc/ludus"
logdir = "/var/log/ludus"
strategy_dir = "/etc/ludus/strategies"
try:
os.makedirs(config_path)
except:
pass
try:
os.makedirs(logdir)
except:
pass
#get external IP using https://ipecho.net/plain service by Google
router_ip = urllib.request.urlopen('https://ipecho.net/plain').read().decode('utf8')
config_file= open(os.path.join(config_path,"ludus.config"), "w")
config = configparser.ConfigParser()
#settings
config.add_section("settings")
config.set("settings","router_ip", router_ip)
config.set("settings","installation_hash", ''.join(random.choices(string.ascii_letters + string.digits, k=HASH_SIZE)))
config.set("settings","timeout", "10")
config.set("settings", "logfile", os.path.join(logdir, "ludus.log"))
config.set("settings","local_stats", "/tmp/ludus_local_data.pkl")
#strategy
config.add_section("strategy")
config.set("strategy", "strategy_dir", strategy_dir)
config.set("strategy", "filename", "secConfDefAtt_1516886661989_-1HPsalgzerosum-bayes-relevant-NE-partial-att-strategy_Ports25")
config.set("strategy", "strategy_url", "http://ludus.aic.fel.cvut.cz/newest.gpg")
#suricata
config.add_section("suricata")
config.set("suricata", "interface", "eth1")
config.set("suricata", "config", os.path.join(config_path, 'suricata_for_ludus.yaml'))
config.set("suricata", "logdir", logdir)
config.write(config_file)
# copy suricata.yaml and update it
#copy strategy files to strategy_dir
os.system(f"cat /etc/suricata/suricata.yaml | sed -e 's&[^$+#]HOME_NET:.*& HOME_NET: \"{router_ip}\"&' | sed -e 's&default-rule-path: .*&default-rule-path: /etc/ludus/rules&' > /etc/ludus/suricata_for_ludus.yaml")
os.system(f"cp -a ./Strategizer/strategies {strategy_dir}")
#donwload rules for suricata
os.system("wget https://rules.emergingthreats.net/open/suricata/emerging.rules.tar.gz")
os.system(f"tar -C {config_path} -xvf emerging.rules.tar.gz")
os.system("rm emerging.rules.tar.gz")
os.system(f"cp ludus-public-key.asc {config_path}")
# register ludus as process
print(colored("Instalation finished! For more information about Ludus project, visit https://www.stratosphereips.org/ludus", "green"))
#print("For starting the tool, type 'COMMAND TODO'.")