generated from stratosphereips/awesome-code-template
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from stratosphereips/cyst-integration
Cyst integration
- Loading branch information
Showing
22 changed files
with
230 additions
and
425 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,24 +2,21 @@ | |
# Arti | ||
# Sebastian Garcia. [email protected] | ||
import sys | ||
from os import path, makedirs | ||
import numpy as np | ||
import random | ||
import pickle | ||
import argparse | ||
import logging | ||
# This is used so the agent can see the environment and game component | ||
sys.path.append(path.dirname(path.dirname(path.dirname(path.dirname(path.dirname(path.abspath(__file__) ) ) )))) | ||
sys.path.append(path.dirname(path.dirname(path.dirname(path.abspath(__file__) )))) | ||
import mlflow | ||
import subprocess | ||
from os import path, makedirs | ||
from AIDojoCoordinator.game_components import Action, Observation, GameState, AgentStatus | ||
|
||
# This is used so the agent can see the environment and game component | ||
# with the path fixed, we can import now | ||
from env.game_components import Action, Observation, GameState | ||
sys.path.append(path.dirname(path.dirname(path.dirname(path.abspath(__file__) )))) | ||
from base_agent import BaseAgent | ||
from agent_utils import generate_valid_actions, state_as_ordered_string, convert_concepts_to_actions, convert_ips_to_concepts | ||
import mlflow | ||
import subprocess | ||
|
||
|
||
class QAgent(BaseAgent): | ||
|
||
|
@@ -383,15 +380,15 @@ def play_game(self, observation_ip, episode_num, testing=False): | |
test_end = test_observation.end | ||
test_info = test_observation.info | ||
|
||
if test_info and test_info['end_reason'] == 'blocked': | ||
if test_info and test_info['end_reason'] == AgentStatus.Fail: | ||
test_detected +=1 | ||
test_num_detected_steps += [num_steps] | ||
test_num_detected_returns += [reward] | ||
elif test_info and test_info['end_reason'] == 'goal_reached': | ||
elif test_info and test_info['end_reason'] == AgentStatus.Success: | ||
test_wins += 1 | ||
test_num_win_steps += [num_steps] | ||
test_num_win_returns += [reward] | ||
elif test_info and test_info['end_reason'] == 'max_steps': | ||
elif test_info and test_info['end_reason'] == AgentStatus.TimeoutReached: | ||
test_max_steps += 1 | ||
test_num_max_steps_steps += [num_steps] | ||
test_num_max_steps_returns += [reward] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,20 @@ | ||
# | ||
# Author: Maria Rigaki - [email protected] | ||
# | ||
from textual.app import App, ComposeResult, Widget | ||
from textual.widgets import Tree, Button, RichLog, Select, Input | ||
from textual.containers import Vertical, VerticalScroll, Horizontal | ||
from textual.validation import Function | ||
from textual import on | ||
from textual.reactive import reactive | ||
|
||
import sys | ||
from os import path | ||
import os | ||
import logging | ||
import ipaddress | ||
import argparse | ||
import asyncio | ||
|
||
from textual.app import App, ComposeResult, Widget | ||
from textual.widgets import Tree, Button, RichLog, Select, Input | ||
from textual.containers import Vertical, VerticalScroll, Horizontal | ||
from textual.validation import Function | ||
from textual import on | ||
from textual.reactive import reactive | ||
from assistant import LLMAssistant | ||
|
||
# This is used so the agent can see the environment and game components | ||
sys.path.append( | ||
path.dirname(path.dirname(path.dirname(path.dirname(path.dirname(path.abspath(__file__)))))) | ||
) | ||
from env.game_components import Network, IP | ||
from env.game_components import ActionType, Action, GameState, Observation | ||
from AIDojoCoordinator.game_components import Network, IP, ActionType, Action, GameState, Observation | ||
|
||
# This is used so the agent can see the BaseAgent | ||
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | ||
|
@@ -558,7 +549,7 @@ def generate_action(self, state: GameState) -> Action: | |
self.network_input[:-3], mask=int(self.network_input[-2:]) | ||
), | ||
} | ||
action = Action(action_type=self.next_action, params=parameters) | ||
action = Action(action_type=self.next_action, parameters=parameters) | ||
else: | ||
self.notify("Please provide valid inputs", severity="error") | ||
elif self.next_action in [ActionType.FindServices, ActionType.FindData]: | ||
|
@@ -567,7 +558,7 @@ def generate_action(self, state: GameState) -> Action: | |
"source_host": IP(self.src_host_input), | ||
"target_host": IP(self.target_host_input), | ||
} | ||
action = Action(action_type=self.next_action, params=parameters) | ||
action = Action(action_type=self.next_action, parameters=parameters) | ||
else: | ||
self.notify("Please provide valid inputs", severity="error") | ||
elif self.next_action == ActionType.ExploitService: | ||
|
@@ -582,7 +573,7 @@ def generate_action(self, state: GameState) -> Action: | |
"target_service": service, | ||
} | ||
action = Action( | ||
action_type=self.next_action, params=parameters | ||
action_type=self.next_action, parameters=parameters | ||
) | ||
break | ||
else: | ||
|
@@ -600,7 +591,7 @@ def generate_action(self, state: GameState) -> Action: | |
"data": datum, | ||
} | ||
action = Action( | ||
action_type=self.next_action, params=parameters | ||
action_type=self.next_action, parameters=parameters | ||
) | ||
else: | ||
parameters = self.data_input | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.