Spaces:
Runtime error
Runtime error
fix startup order
Browse files- env/env.py +48 -40
- tasks/easy.py +1 -2
- tasks/hard.py +3 -1
- tasks/medium.py +11 -3
env/env.py
CHANGED
|
@@ -21,45 +21,53 @@ class DeceptionEnv:
|
|
| 21 |
|
| 22 |
def step(self, action):
|
| 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 |
-
block_attacker(ip)
|
| 60 |
-
reward += 0.3
|
| 61 |
-
self.done = True
|
| 62 |
-
|
| 63 |
-
self.state = logs
|
| 64 |
|
| 65 |
return self.state, reward, self.done, {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
def step(self, action):
|
| 23 |
|
| 24 |
+
reward = 0
|
| 25 |
+
|
| 26 |
+
# Detect attack
|
| 27 |
+
if action == "detect_attack":
|
| 28 |
+
if failed_logins > 3:
|
| 29 |
+
reward += 0.2
|
| 30 |
+
else:
|
| 31 |
+
reward -= 0.1
|
| 32 |
+
|
| 33 |
+
# Detect port scan
|
| 34 |
+
if action == "detect_attack":
|
| 35 |
+
for r in requests_log:
|
| 36 |
+
if isinstance(r, dict) and r.get("type") == "port_scan":
|
| 37 |
+
reward += 0.2
|
| 38 |
+
break
|
| 39 |
+
|
| 40 |
+
# Deploy honeypot
|
| 41 |
+
if action == "deploy_honeypot":
|
| 42 |
+
deploy_honeypot()
|
| 43 |
+
reward += 0.3
|
| 44 |
+
|
| 45 |
+
# Fake database
|
| 46 |
+
if action == "fake_database":
|
| 47 |
+
fake_database()
|
| 48 |
+
reward += 0.2
|
| 49 |
+
|
| 50 |
+
# Block attacker
|
| 51 |
+
if action == "block_ip":
|
| 52 |
+
if logs["suspicious_ips"]:
|
| 53 |
+
ip = logs["suspicious_ips"][0]
|
| 54 |
+
block_attacker(ip)
|
| 55 |
+
reward += 0.5
|
| 56 |
+
self.done = True
|
| 57 |
+
|
| 58 |
+
self.state = logs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
|
| 60 |
return self.state, reward, self.done, {}
|
| 61 |
+
|
| 62 |
+
def state(self):
|
| 63 |
+
|
| 64 |
+
return self.state
|
| 65 |
+
|
| 66 |
+
def action_space(self):
|
| 67 |
+
|
| 68 |
+
return [
|
| 69 |
+
"detect_attack",
|
| 70 |
+
"deploy_honeypot",
|
| 71 |
+
"fake_database",
|
| 72 |
+
"block_ip"
|
| 73 |
+
]
|
tasks/easy.py
CHANGED
|
@@ -6,9 +6,8 @@ def run():
|
|
| 6 |
brute_force()
|
| 7 |
|
| 8 |
env = DeceptionEnv()
|
| 9 |
-
|
| 10 |
env.reset()
|
| 11 |
|
| 12 |
-
|
| 13 |
|
| 14 |
return reward
|
|
|
|
| 6 |
brute_force()
|
| 7 |
|
| 8 |
env = DeceptionEnv()
|
|
|
|
| 9 |
env.reset()
|
| 10 |
|
| 11 |
+
_, reward, _, _ = env.step("detect_attack")
|
| 12 |
|
| 13 |
return reward
|
tasks/hard.py
CHANGED
|
@@ -8,7 +8,6 @@ def run():
|
|
| 8 |
credential_stuffing()
|
| 9 |
|
| 10 |
env = DeceptionEnv()
|
| 11 |
-
|
| 12 |
env.reset()
|
| 13 |
|
| 14 |
total_reward = 0
|
|
@@ -19,6 +18,9 @@ def run():
|
|
| 19 |
_, r, _, _ = env.step("deploy_honeypot")
|
| 20 |
total_reward += r
|
| 21 |
|
|
|
|
|
|
|
|
|
|
| 22 |
_, r, _, _ = env.step("block_ip")
|
| 23 |
total_reward += r
|
| 24 |
|
|
|
|
| 8 |
credential_stuffing()
|
| 9 |
|
| 10 |
env = DeceptionEnv()
|
|
|
|
| 11 |
env.reset()
|
| 12 |
|
| 13 |
total_reward = 0
|
|
|
|
| 18 |
_, r, _, _ = env.step("deploy_honeypot")
|
| 19 |
total_reward += r
|
| 20 |
|
| 21 |
+
_, r, _, _ = env.step("fake_database")
|
| 22 |
+
total_reward += r
|
| 23 |
+
|
| 24 |
_, r, _, _ = env.step("block_ip")
|
| 25 |
total_reward += r
|
| 26 |
|
tasks/medium.py
CHANGED
|
@@ -1,11 +1,19 @@
|
|
| 1 |
from env.env import DeceptionEnv
|
|
|
|
| 2 |
|
| 3 |
def run():
|
| 4 |
|
| 5 |
-
|
| 6 |
|
|
|
|
| 7 |
env.reset()
|
| 8 |
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
return
|
|
|
|
| 1 |
from env.env import DeceptionEnv
|
| 2 |
+
from env.attacker import brute_force
|
| 3 |
|
| 4 |
def run():
|
| 5 |
|
| 6 |
+
brute_force()
|
| 7 |
|
| 8 |
+
env = DeceptionEnv()
|
| 9 |
env.reset()
|
| 10 |
|
| 11 |
+
total_reward = 0
|
| 12 |
+
|
| 13 |
+
_, r, _, _ = env.step("detect_attack")
|
| 14 |
+
total_reward += r
|
| 15 |
+
|
| 16 |
+
_, r, _, _ = env.step("deploy_honeypot")
|
| 17 |
+
total_reward += r
|
| 18 |
|
| 19 |
+
return total_reward
|